字段 id(int) name(nvarchar) dtime(datetime) 7点50算迟到 求迟到最多的人迟到的次数
select name, max(dtime) from 迟到最多 where name in ( select name from (select top(1) name,count(name) as nub from 迟到最多 where name in(select [name] from 迟到最多 where (datename(Hour, dateadd(Minute,10,dtime)))>=8) group by name order by nub desc) as t) group by name
思路
先求都有谁超过了迟到的时间
再求每人的迟到次数 再求谁迟到的最多
再根据这个名字 查询最大的迟到时间 就是迟到迟到最多的人最后一次迟到的时间了
还有一个比较简单点的 常用的 这里也给大家说说
题目是
显示文章、提交人和最后回复时间
select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b