有A表
a b c三个字段B表
a e f所要结果是根据A表的a判断B表里是否存在a这条数据,如果存在则状态为1不存在则为0select a.*,status[判断的状态] from a join b
具体语句不知道怎么写,还希望各位帮助下。
a b c三个字段B表
a e f所要结果是根据A表的a判断B表里是否存在a这条数据,如果存在则状态为1不存在则为0select a.*,status[判断的状态] from a join b
具体语句不知道怎么写,还希望各位帮助下。
select a.*,1 as status from a join b on a.a=b.a
union all
select a.*,0 as status from a left join b on a.a=b.a where a.a is nullselect a.*,1 as status from a where exists(select 1 from b where b.a=a.a)
union all
select a.*,0 as status from a where not exists(select 1 from b where b.a=a.a)
select a.*,status = (case when b.a is not null then 1 else 0 end)
from a left join b on a.a = b.a
select a.*,status = (case when exists(select 1 from b where a.a = b.a) then 1 else 0 end)
from a
select x1.*,case when x2.a is null then '0' else '1' end status
from A x1 left join B x2 on x1.a=x2.a