标签: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 函数
原文地址:http://7456193.blog.51cto.com/7446193/1851339