需要一些帮助才能从同一列中搜索某些组合。
表值:
COLUMN1 COLUMN2 COLUMN3
WF1 Email AA
WF1 Letter BB
WF2 Email AA
WF2 Letter BB
WF2 Pen CC
如果(第 1 列 = WF1)+(第 2 列 = 电子邮件和信函)+(第 2 列 = 信函和第 3 列 = BB),则打印“N”:
COLUMN1 COLUMN2 COLUMN3
**WF1** **Email** AA
**WF1** **Letter** **BB**
WF2 Email AA
WF2 Letter BB
WF2 Pen CC
我尝试了以下查询但卡住了:
select
case
when max(result) = 2
then
case when instrument in ('Email', 'Letter') and gem_contract_type = 'BB'
then 'N'
else 'Y'
end
else
'Y'
end
from(
select column2, column3,
count(*) over (partition by column1 order by column2) result
from
(select * from table1 where column = 'WF1')
);