关于left outer join

表xx: month_id, user_id, service_id ,acct_fee
表yy: month_id, service_id

sql:
select a.*,b.* from xx a left outer join yy b
on a.month_id=b.month_id and a.service_id=b.service_id and a.month_id='201203'
where a.month_id='201203'

sql分析:
1、根据on后面的条件进行a、b表的左关联
(此时结果集中会有a中所有的数据,只是不满足on后条件的不进行关联,但不满足on后条件的对应的b.*都是null)
2、根据where后面的条件对左关联的结果集进行进一步的筛选

猜你喜欢

转载自dongmingzhaifang.iteye.com/blog/1473843