通过PARTITION BY 实现数据的分组

需求:查询出每一个会员最晚发布的一条出租商铺信息

SELECT TOP 4
        LH.ID ,
        LH.Cust_id ,
        LH.Title ,
        LH.AddDate ,
        LH.Classification  --,LH.add_domain domain      
FROM    ( SELECT    LP_HouseRent.ID ,
                    Cust_id ,
                    Title ,
                    AddDate ,
                    Classification ,
                    ROW_NUMBER() OVER ( PARTITION BY Cust_id ORDER BY AddDate DESC ) new_id
          FROM      dbo.LP_HouseRent WITH ( NOLOCK )
                    INNER JOIN dbo.huiyuan ON huiyuan.id = LP_HouseRent.Cust_id
          WHERE     State >= 1
                    AND dbo.huiyuan.Verify > 2  -- AND add_vip =1 AND add_verify >2
        ) LH
WHERE   LH.new_id = 1
ORDER BY LH.AddDate DESC;

 

上一篇:iOS Dev (60) 如何实现 UITextView 中的 placeHolder


下一篇:Android开发之按键、触摸屏和手势输入专业压力测试方法