如果你只是想知道Originator_Acc_ID
一個以上的交易,那麼你可以使用ROW_NUMBER:
select Originator_Acc_ID, Transaction_Amount
from
(
select Originator_Acc_ID, Transaction_Amount,
row_number() over(partition by Originator_Acc_ID order by Originator_Acc_ID) rn
from yourtable
--where Transaction_Amount > 100000
) src
where rn > 1
見SQL Fiddle with demo
如果他們有row_number()
大於一個就意味着他們有更多的比一筆交易。以上將返回所有那些不止一個。如果你只想要一個以上交易帳戶的列表,那麼你可以使用:
select distinct Originator_Acc_ID
from
(
select Originator_Acc_ID, Transaction_Amount,
row_number() over(partition by Originator_Acc_ID order by Originator_Acc_ID) rn
from yourtable
--where Transaction_Amount > 100000
) src
where rn > 1
甚至:
select Originator_Acc_ID
from
(
select Originator_Acc_ID, Transaction_Amount,
row_number() over(partition by Originator_Acc_ID order by Originator_Acc_ID) rn
from yourtable
--where Transaction_Amount > 100000
) src
where rn = 2