答案 0 :(得分:1)
使用dense_rank
函数和派生表是合适的(请注意我在列名中使用了下划线而不是空格):
select group_type
,desk_number
,comments
from
(select *
,dense_rank() over(partition by group_type order by desk_number desc) dr
from mytable) t1
where t1.dr = 1
我制作了一个rextester示例,您可以尝试here
如果您有任何问题,请与我们联系。
答案 1 :(得分:0)
试试这个:
WITH CTE
AS
(
SELECT
SeqNo = ROW_NUMBER() OVER(ORDER BY CAST(DeskNumber AS INT) DESC PARTITION BY GroupType),
GroupType,
DeskNumber,
[Comment]
FROM YourTable
)
SELECT
*
FROM CTE WHERE CTE.SeqNo = 1
答案 2 :(得分:0)
How can I SELECT rows with MAX(Column value), DISTINCT by another column in SQL?
这很好地回答了你的问题,但为了方便起见我将把它转换为<3
SELECT *
FROM table
INNER JOIN
(SELECT comments, MAX([desk number]) AS MaxDesk
FROM table
GROUP BY comments) groupedtable
ON table.[desk number]= groupedtable.[desk number]
AND table.comments= groupedtable.MaxDesk