[sql]sql中分组查询/union/join

分组函数

max
min
sum
avg
count

分组前查询: where条件

查询邮箱中包含a字符的,每个部门的平均工资

分组后查询: having

查询每个部分的员工数
哪个部门员工数大于2

子查询

union联合查询

将两个表结果合并为一张表
1.字段列数一样 2.默认会去重

select name,age from user
union
select name,age from user2;

SQL中连接(JOIN)的用法

select * from student s join classes c on s.cid = c.id;

猜你喜欢

转载自www.cnblogs.com/iiiiiher/p/12718475.html