Oracle 分组排序函数MySQL实现

Oracle

select waybill_no,reserve_delivery_tm from(select ROW_NUMBER() OVER(PARTITION BY T.WAYBILL_NO ORDER BY T.WQS_CREATE_TM DESC) lev,t.* from TL_RESERVE_DELIVERY t) where lev=1 order by WQS_CREATE_TM

MySQL

SELECT waybill_no,reserve_delivery_tm

FROM (

SELECT reserve_delivery_tm, IF(@pdept=heyf_tmp.waybill_no,@rank:=@rank+1,@rank:=1) AS rank,heyf_tmp.waybill_no

FROM (

SELECT *

FROM TL_RESERVE_DELIVERY

ORDER BY waybill_no DESC

) heyf_tmp,(

SELECT @rownum :=0, @pdept := NULL,@rank:=0) a)

result

WHERE result.rank=1;

 

说明:IF(a,b,c)函数是如果a条件成立,那么b,否则c

打赏

作者:

操千曲而后晓声,观千剑而后识器

暂无关键词!