码迷,mamicode.com
首页 > 数据库 > 详细

sql分组查询partition

时间:2015-12-19 15:01:46      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:

select b.STCD,b.STNM,t.EQPTP,t.EXKEY

from ST_STBPRP_B b

left join ST_GATE_R t on b.STCD = t.STCD

where t.TM = (select max(s.tm) as mtm from ST_GATE_R s where s.STCD = b.STCD group by s.STCD)

 

 

select s.* from (

         select t.STCD,b.STNM,t.EQPNO,t.TM,ROW_NUMBER() over (partition by t.stcd ORDER BY t.tm desc) as numtm

         from ST_GATE_R t

         left join ST_STBPRP_B b on b.STCD = t.STCD

) s where s.numtm = 1

sql分组查询partition

标签:

原文地址:http://www.cnblogs.com/adamas21/p/5059104.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!