关于在where 后接case when 查询效率的问题
有个疑问,有时候在写查询时,需要 使用 select case when a.Field ='x' then 'y' when a.ffield2 = …… end from a join b on a.fid = b.fid where case when a.Field ='x' then 'y' when a.ffield2 = …… end in('y','z')
这样的语法。
因为case when 语句比较长,不想在where 后面再写一遍,想改成
select t.* from (
select case when a.Field ='x' then 'y' when a.ffield2 = …… end FCase from a join b on a.fid = b.fid where t.FCase in('y','z')) t
不知道哪种效率高?