select distinct fromsql 题
1. 统计每个部门的平均工资。
SELECT department, AVG(salary) AS avg_salary FROM employees GROUP BY department;
2. 查询工资高于平均工资的员工信息。
SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);
3. 统计每个部门的员工数量。
SELECT department, COUNT(*) AS employee_count FROM employees GROUP BY department;
4. 查询每个部门的最高工资和最低工资。
SELECT department, MAX(salary) AS max_salary, MIN(salary) AS min_salary FROM employees GROUP BY department;
5. 统计每个月份的入职员工数量。
SELECT MONTH(hire_date) AS month, COUNT(*) AS employee_count FROM employees GROUP BY MONTH(hire_date);
6. 查询没有分配到部门的员工信息。
SELECT * FROM employees WHERE department IS NULL;
7. 查询工资排名前10的员工信息。
SELECT * FROM employees ORDER BY salary DESC LIMIT 10;
8. 查询工资在10000到20000之间的员工信息。
SELECT * FROM employees WHERE salary BETWEEN 10000 AND 20000;
9. 查询员工姓“张”的员工信息。
SELECT * FROM employees WHERE last_name LIKE '张%';
10. 查询入职日期在2019年的员工信息。
SELECT * FROM employees WHERE YEAR(hire_date) = 2019;
11. 查询员工的总工资。
SELECT SUM(salary) AS total_salary FROM employees;
12. 查询工资不重复的员工数量。
SELECT COUNT(DISTINCT salary) AS unique_salary_count FROM employees;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。