sqlserver语句改造又想orderby 又想groupby
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sqlserver语句改造又想orderby 又想groupby相关的知识,希望对你有一定的参考价值。
select min(t1.id) id,t1.mrn from dbo.NURSING_RECORD_FORMS t1,EWELL_SYS_USERS t2
where ((t1.total_score>=45 and t1.template_id = 79)) and ward_no = '1000199'
and t1.record_time >='2014-07-14 08:00' and t1.record_time<= '2014-07-15 08:00'
and t1.recorder_code = t2.code group by t1.mrn
上面一段sql 现在是按mrn分组后取id值最小的,现在我想,按mrn区分以后按record_time降序排列以后取第一个,也就是最后记录的那条数据,怎么写?
from (select t1.*,t2.*,
row_number() over (partition by t1.mrn order by record_time desc) as rn
from dbo.NURSING_RECORD_FORMS t1,EWELL_SYS_USERS t2
where ((t1.total_score>=45 and t1.template_id = 79))
and ward_no = '1000199'
and t1.record_time >='2014-07-14 08:00'
and t1.record_time<= '2014-07-15 08:00'
and t1.recorder_code = t2.code
) t
where rn=1本回答被提问者采纳
今天又看到了华为的文章,我又想感慨一下,华为就是个逗逼
以上是关于sqlserver语句改造又想orderby 又想groupby的主要内容,如果未能解决你的问题,请参考以下文章
想要隐藏navigationBar,同时又想支持右滑返回功能