比如这是a表:
然后这是b表:
将a表中的focus_id和b表中的user_id为1的查出它们的总共有多少条
如select count(*)from ......
比如这是a表:
然后这是b表:
将a表中的focus_id和b表中的user_id为1的查出它们的总共有多少条
如select count(*)from ......
用union all是不是sql更清楚一些:
select count(*)
from
(select id from a where a where a.focus_id=1
union all
select user_id from b where b.user_id = 1) T;
5 回答3.3k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
2 回答2.8k 阅读✓ 已解决
1 回答2.4k 阅读✓ 已解决
1 回答2.9k 阅读✓ 已解决
1 回答2k 阅读✓ 已解决
3 回答2.3k 阅读
select count(*) from a, b where a.focus_id=1 and b.user_id = a.focus_id
建议好好学习下sql的联结的用法。针对手头上的表,提出一些问题用SQL解决,多练习下。其实很简单