T-SQL组跳转并获取

时间:2021-09-10 01:27:31

Consider following tables:

考虑如下表:

T-SQL组跳转并获取

How to skip and take groups from the table? Tried using Row_Number() but it doesn't help. Any ideas?

如何跳过并从表中取出组?尝试使用Row_Number(),但没有帮助。什么好主意吗?

Used query

使用查询

;WITH cte AS (SELECT  Room.Id,  Room.RoomName,
                 ROW_NUMBER() OVER 
                 (ORDER BY Room.Id) AS RN
         FROM    Room INNER JOIN
                 RoomDetails ON Room.Id = RoomDetails.RoomId)
SELECT  Id, RoomName
FROM    cte 
WHERE RN = 1

1 个解决方案

#1


4  

You need to use partition as part of the dense_rank function

您需要将分区用作dense_rank函数的一部分

dense_rank() over (partition by roomid) as row

dense_rank()除以(以roomid为分区)为行

see here for some more examples Windowing functions

在这里可以看到更多的窗口函数示例

#1


4  

You need to use partition as part of the dense_rank function

您需要将分区用作dense_rank函数的一部分

dense_rank() over (partition by roomid) as row

dense_rank()除以(以roomid为分区)为行

see here for some more examples Windowing functions

在这里可以看到更多的窗口函数示例