首页 > 数据库技术 > 详细

SQL的ROW_NUMBER函数

时间:2016-05-09 09:42:54      阅读:329      评论:0      收藏:0      [点我收藏+]
with tabs as  
(  
select ROW_NUMBER() over(partition by customerID  order by totalPrice) as rows,customerID,totalPrice, DID from OP_Order  
 )  
select MAX(rows) as 下单次数,customerID from tabs group by customerID 

with tabs as  
 (  
select ROW_NUMBER() over(partition by customerID  order by insDT) as rows,customerID,totalPrice, DID from OP_Order  
)  
 select * from tabs  
where totalPrice in   
(  
select MIN(totalPrice)from tabs group by customerID  
 ) 

注意:在使用over等开窗函数时,over里头的分组及排序的执行晚于“wheregroup byorder by”的执行

select   
ROW_NUMBER() over(partition by customerID  order by insDT) as rows,  
customerID,totalPrice, DID  
from OP_Order where insDT>2011-07-22 

 

SQL的ROW_NUMBER函数

原文:http://www.cnblogs.com/slmdr9/p/5472642.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!