Oracle数据库查询语句示例
时间: 2024-11-30 16:13:52 浏览: 21
在Oracle数据库中,查询语句通常用来获取、更新或删除数据。以下是一些基本的查询语句示例:
1. **查询数据**:
- 获取所有部门名称和员工姓名:
```sql
SELECT Department.Name, Employee.FirstName, Employee.LastName
FROM Department
JOIN Employee ON Department.Department_ID = Employee.Department_ID;
```
2. **筛选数据**:
- 查找某个特定条件下的员工,例如薪资高于平均水平的员工:
```sql
SELECT Employee_ID, FirstName, LastName
FROM Employee
WHERE Salary > (SELECT AVG(Salary) FROM Employee);
```
3. **分组和聚合**:
- 计算每个部门的平均薪资:
```sql
SELECT Department.Name, AVG(Employee.Salary)
FROM Employee
GROUP BY Department.Name;
```
4. **排序结果**:
- 按照薪水降序显示员工列表:
```sql
SELECT *
FROM Employee
ORDER BY Salary DESC;
```
5. **更新数据**:
- 将所有工资小于10000的员工薪资提高10%:
```sql
UPDATE Employee
SET Salary = Salary * 1.1
WHERE Salary < 10000;
```
6. **删除数据**:
- 删除某条特定的记录,如ID为1的员工:
```sql
DELETE FROM Employee
WHERE Employee_ID = 1;
```
在实际使用时,记得结合业务场景和安全措施来编写和执行查询。
阅读全文