sql数据分组取第一条

 select C_ID,C_Category,E_Amount,E_Category,P_A0,P_A1
   ,(CASE WHEN P_A2<0 THEN 0 ELSE P_A2 END)as P_A2                        
   from(select *,ROW_NUMBER() over(PARTITION by C_ID order by P_A1 desc) rownum
   from @temp)t
   where rownum=1
C_ID 是分组的,
P_A1 是排序的
posted @ 2021-04-30 10:44  世人皆萌  阅读(745)  评论(0编辑  收藏  举报