zoukankan      html  css  js  c++  java
  • SQL的ROW_NUMBER函数

    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' 
  • 相关阅读:
    DP实验
    Linux shell学习
    线性排序算法-计数排序
    算法笔试题练习
    堆排序
    node.js初识
    linux下vim命令详解
    html5学习笔记
    有趣的参数收集
    算法学习-归并排序
  • 原文地址:https://www.cnblogs.com/slmdr9/p/5472642.html
Copyright © 2011-2022 走看看