Select a Column in SQL not in Group By

前端 未结 7 1394
忘了有多久
忘了有多久 2020-11-30 02:25

I have been trying to find some info on how to select a non-aggregate column that is not contained in the Group By statement in SQL, but nothing I\'ve found so far seems to

7条回答
  •  执念已碎
    2020-11-30 02:41

    You can do this with PARTITION and RANK:

    select * from
    (
        select MyPK, fmgcms_cpeclaimid, createdon,  
            Rank() over (Partition BY fmgcms_cpeclaimid order by createdon DESC) as Rank
        from Filteredfmgcms_claimpaymentestimate 
        where createdon < 'reportstartdate' 
    ) tmp
    where Rank = 1
    

提交回复
热议问题