语法是CASE expressing WHEN condition THEN return
这里expressing 不是必须的,如果有,就是拿来和condition进行比较的,意即如果有expressing,默认将它和WHEN后面的条件进行=比较,如果真,返回THEN后面的结果。下面是有expressing和没有expressing的两种写法:
或者,我们可以用if方法
if的语法是IF(condition, value_if_true, value_if_false)
SELECT CASE WHEN uid=32 THEN uid ELSE NULL END userIDCASE WHEN uid <>32 THEN uid ELSE NULL END buid
FROM `contacts` WHERE ( contacts.uid = 32 ) OR ( contacts.fuid = 32 )
应该这样写吧:SELECT COUNT(*) FROM tougao_record WHERE accept_company_id=100 AND channel_type=1 AND check_status=6
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)