一.关联查询
1.内连接 inner join
select * from emp where id >12 inner join department;
2.左连接 left join ......on
左表为基准。右表没有就为null
select * from emp where id>12 left join department on emp.did=department.id;
3.右连接 right join .....on
右表为基准。左表没有就为null
select * from emp where id>12 right join department on emp.did=department.id;
4.完全连接(左右表所有记录都存在,一方没有就为null)
select * from emp full join department on emp.did=department.id;
二.分组
1.分组时注意查询字段,只能是统计函数(count,max,min ,avg)
或者是被分组的字段
2.having使用时,后面跟的条件必须是查询的列(字段)之一
select id ,count(name) from emp group by id ;
select id,avg(salary) from emp group by id having salary>12100;、
本文介绍了SQL中关联查询的基本概念及用法,包括内连接、左连接、右连接和完全连接等,并详细解释了如何进行分组查询,以及如何使用having子句过滤分组结果。
2125

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



