一、简介
记录一下模糊查询 分组查询以及子查询的使用
二、使用
假设有数据库中员工表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)
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/275095.html