【发布时间】:2021-03-24 06:09:58
【问题描述】:
我遇到了无法解决的问题。
with t as (
select 'Apple' a, 2016 yr from dual
union all select 'Tesla' a, 2016 yr from dual
union all select 'Microsoft' a, 2016 yr from dual
union all select 'Google' a, 2016 yr from dual
union all select 'Apple' a, 2017 yr from dual
union all select 'Google' a, 2017 yr from dual
union all select 'Apple' a, 2018 yr from dual
union all select 'Amazon' a, 2018 yr from dual
union all select 'Tesla' a, 2018 yr from dual
union all select 'Nvdia' a, 2018 yr from dual
)
select * from t;
如果数据在所有 3 年的“a”列中都存在,我想分配一个值“好” 如果数据在“a”列中存在 2 年任意组合(2016 年、2017 年)或(2017 年、2018 年)或(2016 年、2018 年),则分配值“平均” 如果数据在“a”列中仅存在 1 年(2016 年)或(2017 年)或(2018 年),则分配值“坏”
期望的输出:
我试过(Case)方法,好像不行。
这里的 SQL FIDDLE UK https://dbfiddle.uk/?rdbms=oracle_18&fiddle=7eda42b2658ee571f7a2e66fd57c0c09
【问题讨论】: