表_a
SymbolQuarter Value
S1 Q1 -1
S1 Q2 -1
S1 Q3 -1
S1 Q4 -1
S2 Q1 -1
S2 Q3 -1
S3 Q1 -1
S3 Q3 -1
S3 Q4 -1
S3 Q2 -1
从Table_a,我想获取四分之一的Q1和Q2以及Q3和Q4值均为负的符号。
因此结果应为S1和S3。
select symbol
from Table_a
where Quarter='A' and
Quarter='B' and
Quarter='C' and
Quarter='D' and Value<0
group by symbol
您可以为此使用条件聚合:
select symbol
from Table_a
where value < 0
group by symbol
having max(case when quarter = 'Q1' then 1 else 0 end) = 1
and max(case when quarter = 'Q2' then 1 else 0 end) = 1
and max(case when quarter = 'Q3' then 1 else 0 end) = 1
and max(case when quarter = 'Q4' then 1 else 0 end) = 1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句