当我有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 8682127687now 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=1I 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更多推荐
发布评论