我在表格中有以下行
name, tagid
-------
test1,1
test1,100
test2,2
test2,200
test3,3
test3,300
名称中有重复项。 有没有办法通过获取每个组的最高tagid来选择唯一名称?
答案 0 :(得分:2)
;WITH cte AS
(
SELECT *, ROW_NUMBER() OVER (PARTITION BY name ORDER BY tagid DESC) AS rn
FROM table_1
)
SELECT *
FROM cte
WHERE rn = 1
答案 1 :(得分:2)
select name,max(tagid) as highest_tagid
from tbl
group by name