记录一个SQL语句 case select 1

select Code, CodeName, CodeAlias, ComCode, OtherSign
  from ldcode
 where codetype = ‘edorapptype‘
   and code <> (case
         when (select 1
                 from lccont b
                where b.contno = ‘W86190001290019‘
                  and b.trdingchannel like ‘ZFB%‘) = 1 then
          ‘-9‘
         else
          ‘9‘
       end)
   and othersign = ‘1‘
 order by length(code), code asc

  去掉(case when)

 select Code, CodeName, CodeAlias, ComCode, OtherSign
  from ldcode
 where codetype = ‘edorapptype‘
   and code <> ‘-9‘ and othersign = ‘1‘

  分析case when  1= 1 then ‘-9‘ else ‘9‘ end

(case
         when (select 1
                 from lccont b
                where b.contno = ‘W86190001290019‘
                  and b.trdingchannel like ‘ZFB%‘) = 1 then
          ‘-9‘
         else
          ‘9‘
       end)

  分析 select 1

select 1  from lccont b
                where b.contno = ‘W86190001290019‘
                  and b.trdingchannel like ‘ZFB%‘

  select * ,select 某字段,

可以用来查询表中是否有符合条件的记录(比如select 1 from seckill where id = 1001;),select 1一般用来当作条件使用,比如exists( select 1 from 表名)等。select 1的效率比select 列名select*快,因为不用查字典表。

记录一个SQL语句 case select 1

上一篇:idea与mysql进行数据交互的出现中文乱码的解决方案


下一篇:mysql容器里不能识别中文输入