LEFT JOIN song b ON a.id = b.cid
LEFT JOIN lai c ON a.id = c.cid
GROUP BY yfdj
select t1.*,IFNULL(t2.num, 0) jf/** 积分*/from (select * from A)t1, (select userid, sum(jifen) num from B group by userid)t2
where t1 left join t2 on t1.userid = t2.userid
/** sql未测试,理论可行 */
这个关联查询一下就可以select a.ida as id ,(a.numa+isnull(b.numb,0)) as num from sa a left join sb b on a.ida=b.idb
union all
select b.idb as id ,b.numb as num from sa a right join sb b on a.ida=b.idb where a.ida is null
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)