首页 > 数据库技术 > 详细

记录一个SQL语句 case select 1

时间:2020-11-12 17:28:27      阅读:24      评论:0      收藏:0      [点我收藏+]
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

原文:https://www.cnblogs.com/zytcomeon/p/13964742.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!