我有以下表格值,
1 11 1 KUTH MUT1 96290 11-OCT-16
7 17 7 KUTH MUT1 96290 13-OCT-16
10 20 10 KUTH MUT1 96290 13-OCT-16
2 12 2 KUTH MUT1 2 11-OCT-16
3 13 3 KUTH MUT1 3 11-OCT-16
4 14 4 KUTH MUT1 4 11-OCT-16
5 15 5 KUTH MUT1 5 11-OCT-16
6 16 6 KUTH MUT1 6 13-OCT-16
8 18 8 KUTH MUT1 8 13-OCT-16
9 19 9 KUTH MUT1 9 13-OCT-16
预期产出:
{{1}}
答案 0 :(得分:1)
SELECT seqno,bill_no,bill_seq,first_name,last_name,phone_number,inserted date
FROM (
SELECT seqno,bill_no,bill_seq,first_name,last_name,phone_number,inserted date
, ROW_NUMBER () OVER (PARTITION BY phone_number ORDER BY seqno) AS rank
FROM table)
ORDER BY phone_number,rank
答案 1 :(得分:0)
虽然目前还不是很清楚你是在寻找2个查询还是1个,但我认为这就是你要找的:
select
seqno, bill_no, bill_seq, first_name, last_name, phone_number, inserted date
from
table
group by
phone_number, seqno, bill_no, bill_seq, first_name, last_name, inserted date
order by
phone_number, seqno asc
答案 2 :(得分:0)
您想先按每个电话号码组的最小值seq_number订购所有行,然后在每个组中按insert_date订购吗?
然后我猜这会做到:
SELECT seqno,bill_no,bill_seq,first_name,last_name,phone_number,inserted_date FROM( SELECT seqno,bill_no,bill_seq,first_name,last_name,phone_number,inserted_date ,MIN(seqno)OVER(按电话号码分区)至少 FROM table1)X ORDER BY minimum,inserted_date