-- mysql 值为空则返回 0 : mysql--> ifnull oracle --> nvl
select category.id as c_id, category.category_id , category.category_name , ifnull(rule.rule_id,0) is_selected
from
goods_category categoryLEFT JOIN integral_relation_category rule
on category.category_id = rule.category_id
-- 为空 返回0 不为空 则返回1 : is not null : true-->1 false--> 0
select category.id as c_id, category.category_id , category.category_name ,
(rule.rule_id is not null) is_selected
from
goods_category categoryLEFT JOIN integral_relation_category rule
on category.category_id = rule.category_id
-- 为空 返回0 不为空 返回1 : if (column is null ,0 ,1)
select category.id as c_id, category.category_id , category.category_name ,
if(rule.rule_id is null,0,1) is_selected
from
goods_category categoryLEFT JOIN integral_relation_category rule
on category.category_id = rule.category_id
查询结果如下: