IF account_no>'1000000'和offset_account='6XXX'那么如果表中再次出现列的值---(security_no AND asofdate AND abs(qty((则(1(否则(0(。
sub_no account_no rep security_no symbol asofdate abs_qty new_column
177 12345 X 2000 A 20180101 100 1
177 23456 Y 2000 A 20180101 100 1
177 34567 Z 5000 A 20180101 300 0
177 45455 Z 5000 A 20170909 300 0
第一行的值应该是1,因为security_no、asofdate和abs_qty列下的值与第2行的值完全相同。
第二行的值应该为1,因为security_no、asofdate和abs_qty列下的值与第1行的值完全相同。
第三行的值应该为0,因为security_no、asofdate和abs_qty列下的值与表中的任何其他行都不相同。
第四行的值应该为0,因为security_no、asofdate和abs_qty列下的值与表中的任何其他行都不相同。
我认为您可以使用窗口函数来执行您想要的操作:
select t.*,
(case when count(*) over (partition by security_no, asofdate, abs_qty) > 1
then 1 else 0
end) as new_column
from t;