distinct与groupby 相似,但不同的是group by 可以与聚合一起使用,而distinct不能
对于不包含聚集函数的GROUP BY操作来说,和DISTINCT操作是等价的。不过虽然二者的结果是一样的,二者的执行计划不同
groupby后排序
distinct后的排序
SELECT RoomTypeCode, NumberOfCots, Count(*) as NumberOfRooms
FROM [dbo].[BookHotelPax]
WHERE
(BookId = '816' AND
ItemReference = '1')
GROUP BY RoomTypeCode,NumberOfCots
ORDER BY MIN(AutoId) a
select typeid from (select id=min(id),Typeid from product group by typeid)a order by a.id desc