当我有7个时,在3列上有所区别(Distinct on 3 columns when I have 7)

编程入门 行业动态 更新时间:2024-10-28 16:19:05
我有7个时,在3列上有所区别(Distinct on 3 columns when I have 7)

我希望使用db2这样的输出...

NR TAG1 TAG2 someData1 someData2 ========================================= 1 Class1 2015 11665456 862187687 1 Class1 2014 33254665 86221187687 1 Class1 2013 55557321 8687687787 2 Class2 2015 21654765 86822117687 2 Class2 2014 57658776 8632187687 2 Class2 2013 54878575 8682127687

现在我尝试但未能编写SQL代码以在前3行中具有Distinct。

当我尝试用(*)获取所有数据时,我得到865条记录。

当我只拿前3行并忽略其余的不同时,我得到808条记录。

但我不知道如何显示其余的数据。

I want an output like this table using db2...

NR TAG1 TAG2 someData1 someData2 ========================================= 1 Class1 2015 11665456 862187687 1 Class1 2014 33254665 86221187687 1 Class1 2013 55557321 8687687787 2 Class2 2015 21654765 86822117687 2 Class2 2014 57658776 8632187687 2 Class2 2013 54878575 8682127687

now I trying but failing to write an SQL Code to have a Distinct on the first 3 rows.

When I try to get all data with (*) I get 865 records.

When I only take the first 3 rows and ignore the rest with distinct I get 808 records.

But I dont know how to show the rest of the data.

最满意答案

我认为你只想考虑前三个COLUMNS并显示结果来删除重复项。 如果我的理解有误,请进一步解释。

with cte as (select *, row_number() over(partition by NR, TAG1, TAG2 order by NR, TAG1, TAG2) as row_num from Table_name) select * from cte where row_num=1

I presume you want to remove duplicates by considering only first three COLUMNS and display the result. If my understanding is wrong, please explain further.

with cte as (select *, row_number() over(partition by NR, TAG1, TAG2 order by NR, TAG1, TAG2) as row_num from Table_name) select * from cte where row_num=1

更多推荐

本文发布于:2023-07-27 14:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1292030.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我有   区别   columns   Distinct

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!