计算a、b两个表中,值相等的某一列的数量
group by … count()
创建分组并且用聚集函数进行计算
inner join—同时存在
内联结—在两个表的交集中进行操作
select a.id,COUNT(b.Id ) from a right outer join a ON a.** = b.** group by material.id;
取得a,b两个表 相等的**列的值。每个值都同时存在于a,b两个表中
left (outer) join
左外联结—在左表的集合中进行操作
select a.id,COUNT(b.Id ) from a left outer join a ON a.** = b.** group by material.id;
right (outer) join
右外联结—在右表的集合中进行操作
select a.id,COUNT(b.Id ) from a right outer join a ON a.** = b.** group by material.id;
参考资料:
https://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins