sql 分组后取第一条数据

select * from (
select *,ROW_NUMBER() OVER(partition by OrderDate,PackageNo,BatchCode,SortLine order by SortLine) as new_index
from table) t where new_index=1

 

 

partition by 表示分组的字段 

order by 表示每个分组内的结果集排序

posted @ 2022-05-07 15:32  流年sugar  阅读(815)  评论(0编辑  收藏  举报