-5

我有这种类型的桌子。

no    CustID             Amount
1     1234               1000
2     2345                500
3     1234               1000
4     6789                500
5     1234               1000
6     6789                350
7     2345                600    
8     1234                250

我需要这样的输出

No    CustId             Amount
1     1234               1000
2     1234               1000
3     1234               1000
4     1234                250
1     2345                500
2     2345                600
1     6789                500
2     6789                350

请为此提供Sql

4

3 回答 3

2
SELECT row_number() over (partition by CustId order by Amount desc) No, 
CustId, Amount
FROM <table>
ORDER BY CustId, Amount DESC
于 2013-10-16T10:17:22.863 回答
1

由于要根据组中的客户 ID 分配行号,因此以下查询将在 T-SQL 中工作:

select ROW_NUMBER () over (partition by CustID order by Amount desc) as [No],CustID,Amount
from table1
于 2013-10-16T10:17:53.633 回答
-1
select * from TABLE_NAME order by CustId;
于 2013-10-16T10:14:23.463 回答