初入Sql Server 之分组查询方式等其他查询方式
作者:互联网
一、简介
记录一下模糊查询 分组查询以及子查询的使用
二、使用
假设有数据库中员工表employee(e_id,e_name,d_id,e_salary) 和部门表department(d_id,d_name),
2.1 分组查询 GROUP BY
按部门分组,筛选条件为部门平均工资大于7000
SELECT d_id AS '部门编号', AVG(e_salary) AS '部门平均工资' FROM employee GROUP BY d_id HAVING AVG(e_salary) > 7000
2.2 模糊查询 LIKE
查询部门中,姓王的员工
SELECT * FROM employee WHERE LIKE '王%'
2.3 子查询
查找部门编号最小的员工信息
SELECT * FROM employee WHERE d_id = (SELECT MIN(d_id) FROM department)
标签:Server,初入,部门,分组,employee,查询,id,SELECT 来源: https://www.cnblogs.com/just-like/p/16488308.html