记录一个SQL语句 case select 1

时间:2023-03-10 03:37:28
记录一个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*快,因为不用查字典表。