方案:通过union连接查询出所有需要的特殊标签,然后在通过left join与union中的结果集做多表比较。
sql
select t.`code`,a.`count` as count_a,b.`count` as count_b from( select `code` from tmp_a a union select `code`from tmp_b b) t left join tmp_a a on t.`code`=a.`code` left join tmp_b b on t.`code`=b.`code`;
两张表
select * from tmp_a; select * from tmp_b;
本文介绍了一种使用SQL的union和left join进行多表数据比较的方法,通过具体示例展示了如何从两个临时表中选取特定字段,并进行数据整合。
10万+

被折叠的 条评论
为什么被折叠?



