hyfm.net
当前位置:首页 >> mysql联合查询问题(将学生信息和对应的考勤次数联合返回,最好能用考勤次数排序) >>

mysql联合查询问题(将学生信息和对应的考勤次数联合返回,最好能用考勤次数排序)

select a.*,b.考勤次数 from 学生信息表 a (select s_id,count(*) as 考勤次数 from 学生考勤表 group by s_id)b where a.s_id=b.s_id order by b.考勤次数 desc;

先执行ab两个表联合查询后形成的查询结果再与c进行查询

可以这样查询select stanumber,sum( case when check = '缺勤' then 1 end) as 缺勤次数,sum( case when check = '迟到' then 1 end) as 迟到次数from table1group by stanumber

用order by 来排序 select "栏位名" from "表格名" [where "条件"] order by "栏位名" [asc, desc] asc从小到大 desc从大到小

sqlserver写法1234select a.user_name,sum(b.worktime) as worktimefrom users as a,time_entries as b where a.user_id=b.user_idand convert(varchar(10),updated_on,120)='2014-01-01'--时间写法是sqlserver写法,时间自行改一下group by a.user_name having sum(b.worktime) 全部

按长度排序的方法:select *,len(id) len_id from image where title like '%XXXX%' order by len_id descunion不能使用order,你这样的需求应该是把两次查询的结果保存到临时表里面,然后从临时表里面获数据.使用临时表的方法能方便的实现去除重复.

相关文档
alloyfurniture.com | 369-e.com | 3859.net | jinxiaoque.net | gmcy.net | 网站首页 | 网站地图
All rights reserved Powered by www.hyfm.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com