SQL 查询获取列表中每个元素的前 1 个值

发布于 2024-11-09 05:12:45 字数 297 浏览 0 评论 0原文

在此处输入图像描述

我需要帮助编写返回所有列的查询

select id, city, road1, road2, lat, long 
from tbltest 
group by id, city, lat, long. 

最终结果应该是这样的在此处输入图像描述

谢谢, 帕万

enter image description here

I need help in writing a query which returns me all columns

select id, city, road1, road2, lat, long 
from tbltest 
group by id, city, lat, long. 

The final result should have something like thisenter image description here

Thanks,
Pawan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

桃气十足 2024-11-16 05:12:45

虽然很奇怪,但该表有重复的 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

Although it is weird, that the table has duplicate id columns here is the query that would show the result you need:

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
偏爱你一生 2024-11-16 05:12:45

使用公用表表达式

;with tbl as
(
    select *, row_number() over(partition by id, city order by road1, road2) RowNumber
    from tbltest 
)

select * from tbl
where RowNumber = 1

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文