我需要帮助编写一个返回所有列的查询
select id, city, road1, road2, lat, long
from tbltest
group by id, city, lat, long.
最终结果应该是这样的
谢谢, 爬完
答案 0 :(得分:2)
虽然很奇怪,但是这里的表有重复的id列,这个查询会显示你需要的结果:
select id, city, road1, road2, lat, long
from
(
select *, row_number() over(partition by id, city, lat, long order by road1, road2) RowNumber
from tbltest
) tt
where RowNumber = 1
答案 1 :(得分:0)
Using Common Table Expressions
;with tbl as
(
select *, row_number() over(partition by id, city order by road1, road2) RowNumber
from tbltest
)
select * from tbl
where RowNumber = 1