一句話
case then 解決
詳細點
case when count(1)>0 then count(1) else 0 end countnum;
如果還不懂,看個案例,
兩張表 tb_ent_activity_info ,tb_ent_activity_log, info 的id關聯 log裏面的activity_id
一張信息表(表字段太多,不做介紹),一張日誌表(id,activity_id,user_id,create_time)
採用左連接查詢,日誌表爲空的不爲0
稍作修改
就是辣麼簡單~~
注:不要用 case不要傳入列名參數
即case countnumber when …這種寫法,數據會錯的