我们可以使用switch case以这种方式过滤表的列吗?
select distinct stud.name, stud.num,
case WHEN stud.sub like '%data%' THEN stud.sub
WHEN stud.sub like '%informatics%' THEN stud.sub
WHEN stud.sub like '%genomics%' THEN stud.sub
ELSE '---'
END
from table_A
预期结果是
Name ID Sub
victor 2098 -----
Lui 6754 Bioinformatics
Willis 7653 Advanceddatascience
谢谢!
答案 0 :(得分:0)
是的,您的查询应该有效。如果你想尝试不同的东西,这应该在Oracle中有效。很容易将其更改为任何其他RDBMS。 也很容易添加任何其他主题。
With aux as ( select '%data%' as auxText from dual union all
select '%informatics%' as auxText from dual union all
select '%genomics%' as auxText from dual )
select distinct stud.name, stud.num,
nvl(stud.sub,'---') as sub
from table_A left join aux on table_A.sub like aux.auxText;