码迷,mamicode.com
首页 > 数据库 > 详细

mysql 函数

时间:2016-09-10 14:48:12      阅读:284      评论:0      收藏:0      [点我收藏+]

标签:mysql 函数



order by id desc查询唯按次序排列

select top 6*from [ViewCMPP_SendCentreMo] where SendType = ‘扣费‘ order by id desc; 

这个速度快些

select top 6*from [ViewCMPP_SendCentreMo] where SendType = ‘扣费‘ order by SendCentreID desc, id desc; 




COUNT统计和group by 1 分组 

SELECT COUNT(*) FROM employee_tbl group by 1;



case when then 多条件判断 

解释 查询 id, name, cj,字段 为 cj < 60 THEN ‘不及格‘  

WHEN cj BETWEEN 60 AND 90 THEN ‘良好‘ 为满足 60和90 为真否责查询为空

SELECT     id, name, cj, (CASE WHEN cj < 60 THEN ‘不及格‘ WHEN cj BETWEEN 60 AND 90 THEN ‘良好‘ WHEN cj > 90 THEN ‘优秀‘ END) AS 状态 FROM   stud;  



distinct查询唯一 后面加排序   

$user=123

select distinct shuozhe,tingzhe from sixin where (shuozhe=‘$user‘ or tingzhe=‘$user‘) order by  id desc  " ; 




LENGTH求长度 

SELECT * FROM admin WHERE LENGTH(username) < 6;



sum求和 as别名 

SELECT SUM(salary) as "Total Salary" FROM employees WHERE salary > 25000;



多表查询 

如:SELECT a.id,a.name,a.address,b.math,b.english,b.chinese FROM tb_demo065 a,tb_demo065_tel b WHERE a.id=b.id AND b.id=‘$_POST[textid]‘;



或者下面从tb_chengji和tb_info数据表中查询yuwen大于等于100的数据记录。代码如下

select tb_chengji.id,tb_chengji.xuesheng,xingbie,dizhi,yuwen,shuxue,yingyu from

tb_chengji,tb_info where tb_chengji.xuesheng=tb_info.xuesheng and tb_chengji.yuwen>=100;




本文出自 “秋水无痕” 博客,谢绝转载!

mysql 函数

标签:mysql 函数

原文地址:http://7456193.blog.51cto.com/7446193/1851339

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!