【发布时间】:2019-07-18 10:08:42
【问题描述】:
我的桌子看起来像:
cust_ref | account_num
123456 | 001132
321234 | 123213
325123 | 412312
123456 | 312321
我基本上要做的是将重复的 cust_ref 行排序在一起并对其进行排序,以便所有重复项从第 1 行开始按降序排列。即,如果有一个对应于 3 个 account_num 的 cust_ref 编号,那么它将位于对应于 2 个 account_num 的 cust_ref 的较高行
例如
cust_ref | account_num
123456 | 001132
123456 | 312321
321234 | 123213
325123 | 412312
我当前的查询是:
select cust_ref,
account_num
from (
select cust_ref,
account_num,
max(phone_num)
from table_name
group by cust_ref, account_num
)
【问题讨论】:
-
什么是 RDBMS?甲骨文、MSSQL、mysql、PostgreSql……?请添加您的 RDBMS 的标签。
标签: sql oracle duplicates sql-order-by