常用的方法有:子查询.ROW_NUMBER.APPLY,总体感觉还是ROW_NUMBER比较直观 if OBJECT_ID('testGroup') is not null drop table testGroup GO create table testGroup ( ID int identity primary key, UserID int, OrderID int ) GO insert testGroup , union all , union all , union all , u