sql中case的用法

sql中case的用法,第1张

case 列 when 值1 then 值2 --当列的值等于值1 就返回值2

when 值3 then 值4 --当列的值等于值3 就返回值4

end

case when 列=值1 then 值2 --当列的值等于值1 就返回值2

when 列=值3 then值4 --当列的值等于值3 就返回值4

end

if 作为条件判断,一般用在存储过程或者函数里面;

譬如

if sqlstate ='02000' then

select xxx from tab

case是作为判断,用在查询当中

select id, case when id = 1 then 'one' else 'null' end

高效两个没有可比性,深究一点,都是一个逻辑判断,然后出结果,所以旗鼓相当,没必要在这个问题上探究性能问题

switch (i){

case 0:

CaseZero()

break

case 1:

CaseOne()

break

case 2:

default//单词错了

CaseTwo()

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/9628072.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-30
下一篇 2023-04-30

发表评论

登录后才能评论

评论列表(0条)

保存