MySQL查询语句之【排序去重分组】1.MySQL排序:(order by)
1.升序 :ASC(默认)
语法:select * from 数据表名 order by 字段名 ASC;
mysql语句分类
2. 降序: DESC
语法:select * from 数据表名 order by 字段名 DESC;
js获取当前日期-- 排序默认升序
select * from mytable2 order by brith ;
-- 降序排序
select * from mytable2 order by brith DESC;
字符串长度为0-- 升序排序
select * from mytable2 order by brith ASC;
js正则表达式匹配指定字符只出现一次2.MySQL去重:(union)
语法 :select * from table1 [where⼦句] union select * from table2 [where⼦句];
union 后可加all ,也可加distinct。默认为 union distinct。
1.select * from table1 [where⼦句] union all select * from table2 [where⼦句];
保留结果集中重复的数据。
2.select * from table1 [where⼦句] union distinct select * from table2 [where⼦句];
删除结果集中重复的数据,每条数据只保留⼀条。
3.MySQL分组:(group by)
1.简单分组并统计每组个数:group by
-- 按照名字分组并显⽰每组个数
select name ,count(*) AS '个数' from employee_tbl GROUP BY name ;
c语言简单的程序
以下关于任意文件上传漏洞原理
2.显⽰每组signin字段的和:with rollup 再次统计
-- 按照名字分组后再统计signin的总数
select name,sum(signin) from employee_tbl GROUP BY name with rollup;
3.为空值设置name:coalesce()函数
-- coalesce(a,b,c)函数如果a为空就取b值,b为空就取c值,c为空就返回null
select coalesce (name,'总数') ,sum(signin) from employee_tbl group by name with rollup;
coalesce() 与 ifnull()两函数的区别:ifnull函数只能接收两个参数,意义为:如果第⼀个为空,则选择第⼆个参数;⽽coalesce函数可以接收两个或多个参数,如果第⼀个为空,则选择第⼆个参数,第⼆个为空则选择第三个参数... ...以此类推。
if(expr,值1, 值2):如果expr为true,返回值1;否则,返回值2;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。