查询多个结果是用case when 条件显示列的查询效率高,还是查询后union all合并效率高.
比如selectname,casebzwhen1thengongzhielse0endasf1,casebzwhen2thengongzhielse0endasf2fro...
比如
select name,case bz when 1 then gongzhi else 0 end as f1 ,case bz when 2 then gongzhi else 0 end as f2
from 工资表
-------
select name, case bz when 1 then gongzhi else 0 end as f1 , 0 as f2
from 工资表
union all
select name, 0 as f1 ,case bz when 2 then gongzhi else 0 end as f2
from 工资表
哪个效率高? 展开
select name,case bz when 1 then gongzhi else 0 end as f1 ,case bz when 2 then gongzhi else 0 end as f2
from 工资表
-------
select name, case bz when 1 then gongzhi else 0 end as f1 , 0 as f2
from 工资表
union all
select name, 0 as f1 ,case bz when 2 then gongzhi else 0 end as f2
from 工资表
哪个效率高? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询