SQL如何查询员工ID为1001的信息? 如何查询所有员工的姓名和工资? 如何查询所有员工的入职日期和所在部门? 如何查询所有员工的年龄和性别? 如何查询所有男性员工的信息? 如何查询所有工资大于等于5000的员工信息? 如何查询所有工资在4000到6000之间的员工信息? 如何查询所有入职日期在2019年的员工信息? 如何查询所有职位为经理的员工信息? 如何查询所有在部门D1工作的员工信息? 如何查询所有在部门D1或D2工作的员工信息? 如何查询所有员工的工资总和? 如何查询所有员工的平均工资? 如何查询所有部门的员工总数? 如何查询所有部门的平均工资? 如何查询所有部门的最高工资? 如何查询所有部门的最低工资? 如何查询所有员工的最高工资? 如何查询所有员工的最低工资? 如何查询所有员工的工资排名?
时间: 2024-02-12 14:05:59 浏览: 123
部门表、员工表和工资等级表的SQL文件
好的,我可以为您逐一回答这些问题,请参考下面的SQL语句:
1. 查询员工ID为1001的信息:
```sql
SELECT * FROM employees WHERE employee_id = 1001;
```
2. 查询所有员工的姓名和工资:
```sql
SELECT first_name, last_name, salary FROM employees;
```
3. 查询所有员工的入职日期和所在部门:
```sql
SELECT hire_date, department_name
FROM employees
JOIN departments ON employees.department_id = departments.department_id;
```
4. 查询所有员工的年龄和性别:
```sql
SELECT TRUNC(MONTHS_BETWEEN(SYSDATE, birth_date) / 12) age, gender
FROM employees;
```
5. 查询所有男性员工的信息:
```sql
SELECT * FROM employees WHERE gender = 'M';
```
6. 查询所有工资大于等于5000的员工信息:
```sql
SELECT * FROM employees WHERE salary >= 5000;
```
7. 查询所有工资在4000到6000之间的员工信息:
```sql
SELECT * FROM employees WHERE salary BETWEEN 4000 AND 6000;
```
8. 查询所有入职日期在2019年的员工信息:
```sql
SELECT * FROM employees WHERE hire_date BETWEEN TO_DATE('2019-01-01', 'YYYY-MM-DD') AND TO_DATE('2019-12-31', 'YYYY-MM-DD');
```
9. 查询所有职位为经理的员工信息:
```sql
SELECT * FROM employees WHERE job_title = 'Manager';
```
10. 查询所有在部门D1工作的员工信息:
```sql
SELECT * FROM employees WHERE department_id = 'D1';
```
11. 查询所有在部门D1或D2工作的员工信息:
```sql
SELECT * FROM employees WHERE department_id IN ('D1', 'D2');
```
12. 查询所有员工的工资总和:
```sql
SELECT SUM(salary) FROM employees;
```
13. 查询所有员工的平均工资:
```sql
SELECT AVG(salary) FROM employees;
```
14. 查询所有部门的员工总数:
```sql
SELECT departments.department_name, COUNT(*) AS total_employees
FROM employees
JOIN departments ON employees.department_id = departments.department_id
GROUP BY departments.department_name;
```
15. 查询所有部门的平均工资:
```sql
SELECT departments.department_name, AVG(employees.salary) AS avg_salary
FROM employees
JOIN departments ON employees.department_id = departments.department_id
GROUP BY departments.department_name;
```
16. 查询所有部门的最高工资:
```sql
SELECT departments.department_name, MAX(employees.salary) AS max_salary
FROM employees
JOIN departments ON employees.department_id = departments.department_id
GROUP BY departments.department_name;
```
17. 查询所有部门的最低工资:
```sql
SELECT departments.department_name, MIN(employees.salary) AS min_salary
FROM employees
JOIN departments ON employees.department_id = departments.department_id
GROUP BY departments.department_name;
```
18. 查询所有员工的最高工资:
```sql
SELECT MAX(salary) FROM employees;
```
19. 查询所有员工的最低工资:
```sql
SELECT MIN(salary) FROM employees;
```
20. 查询所有员工的工资排名:
```sql
SELECT employee_id, salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS salary_rank
FROM employees;
```
阅读全文