本文介绍了如何根据两个不同的列获取记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个包含三列的表,有一些记录,我想选择第1列和第3列如果多次出现的记录



这意味着不同的column1和column3







更好地理解



if i have a table containing three columns, with some records, I want to select records in which column 1 and column3 comes once if they are multiple times

That means distinct column1 and column3



For Better Understanding

column1 column2 column3
user1   a1  category1
user2   a2  category2
user1   a3  category2
user1   a4  category1
user3   a5  category2


Output

column1 column2 column3
user1   a1  category1
user2   a2  category2
user1   a3  category2
user3   a5  category2

推荐答案

Select Column1, Column2, Column3
FROM
(
    SELECT ROW_NUMBER() over (Partition By Column1, Column3 Order by Column1, Column3) as Rownr, Column1, Column2, Column3
    FROM Table1
) as DataSet
where Rownr = 1


这篇关于如何根据两个不同的列获取记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 17:16