Mysql语句---group by/having, inner join, left join , right join

计算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两个表中
Mysql语句---group by/having, inner join, left join , right join_第1张图片

left (outer) join

左外联结—在左表的集合中进行操作
select a.id,COUNT(b.Id ) from a left outer join a ON a.** = b.** group by material.id;
Mysql语句---group by/having, inner join, left join , right join_第2张图片

right (outer) join

右外联结—在右表的集合中进行操作
select a.id,COUNT(b.Id ) from a right outer join a ON a.** = b.** group by material.id;

Mysql语句---group by/having, inner join, left join , right join_第3张图片

参考资料:

https://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins

你可能感兴趣的:(数据库)