如何在返回sql server中的所有列的同时基于两列或更多列来区分数据库表中的行

时间:2021-10-29 02:01:33

I want to distinguish Rows on the basis of two or more columns value of the same table at the same time returns all columns from the table. Ex: I have this table DB Table

我想在同一时间基于两个或多个列的值来区分Rows返回表中的所有列。例如:我有这个表DB表

I want my result to be displayed as: filter on the basis of type and Number only. As in abover table type and Number for first and second Row is same so it should be suppressed in result.

我希望我的结果显示为:仅基于类型和数字进行过滤。如在abover表类型和第一行和第二行的数字相同所以它应该在结果中被抑制。

txn item Discrip Category type   Number            Mode
60  2    Loyalty    L     6174  XXXXXXX1390         0
60  4    Visa       C     1600  XXXXXXXXXXXX4108    1

I have tried with sub query but yet unsuccessful. Please suggest what to try. Thanks

我尝试过子查询但是不成功。请建议尝试一下。谢谢

1 个解决方案

#1


4  

You can do what you want with row_number():

你可以用row_number()做你想做的事:

select t.*
from (select t.*,
             row_number() over (partition by type, number order by item) as seqnum
      from t
     ) t
where seqnum = 1;

#1


4  

You can do what you want with row_number():

你可以用row_number()做你想做的事:

select t.*
from (select t.*,
             row_number() over (partition by type, number order by item) as seqnum
      from t
     ) t
where seqnum = 1;