[pgsql-jp: 28759] Re: SQL文での条件判定について

Iso, Toshitaka Toshitaka.Iso @ hp.com
2003年 1月 24日 (金) 18:50:54 JST


Yu Ooasaさん、仲村さん

ご返答ありがとうございます。

確かにテーブルを追加すれば出来そうなのですが
テーブルを追加するのは厳しそうなんです。

SQLでは(こちらも別の方にお知恵を借りたものですが…)
カラム2ごとではなく、全レコードに対して判定を行うのは出来そうです。

select * from A
where
((exists(select * from A where Col3 in('0400')) and Col3='0400') 
or (not exists(select * from A where Col3 in ('0400')) and Col3='0500')
or (not exists(select * from A where Col3 in ('0400','0500')) and Col3='0600')
or (not exists(select * from A where Col3 in ('0400','0500','0600')) and Col3='0700')
or (not exists(select * from A where Col3 in ('0400','0500','0600','0700')) and Col3='0300')
or (not exists(select * from A where Col3 in ('0400','0500','0600','0700','0300')) and Col3='0200')
or (not exists(select * from A where Col3 in ('0400','0500','0600','0700','0300','0200')) and Col3='0100'));

P.S. すみません。優先順位は
0400>0500>0600>0700>0300>0200>0100
の間違いでした。。

以上です。



pgsql-jp メーリングリストの案内