911 浏览
喜欢(9)

SQL Server 使用ROW_NUMBER和GROUP BY分组查询每组的第一条和最后一条数据记录

假如我们有个分组查询的需求,要求按照指定字段进行分组并同时查询出分组字段的第一条和最后记录,大致数据如下:UNION查询1:SELECT 1 AS ID, 110 AS TRAIN_IDUNIONSELECT 2 AS ID, 111 AS TRAIN_IDUNIONSELECT 3 AS ID, 112 AS TRAIN_IDUNION查询2:SELECT 110 AS TRAIN_ID , 1 AS ID,11111 NUM...

SQL Server 2015-12-14 13:48 0评论 0收藏
AD 友情赞助