写出里面的SQL命令
时间: 2024-10-25 14:02:12 浏览: 10
SQL优化,数据库优化技能。
以下是文档中提到的各个SQL命令:
1. **查询student表的所有记录**:
```sql
SELECT * FROM student;
```
2. **用in关键字查询student表中中文系和英语系的学生信息**:
```sql
SELECT * FROM student WHERE department IN ('中文系', '英语系');
```
3. **查询student表年龄在18~20岁的学生信息**:
```sql
SELECT * FROM student WHERE YEAR(CURDATE()) - YEAR(birth) BETWEEN 18 AND 20;
```
4. **查询student表每个院系有多少人**:
```sql
SELECT department, COUNT(*) AS count FROM student GROUP BY department;
```
5. **查询score表每个考试科目的平均成绩**:
```sql
SELECT c_name, AVG(grade) AS average_grade FROM score GROUP BY c_name;
```
6. **用连接方式查询姓张或者姓王的同学的姓名、院系和考试科目及成绩**:
```sql
SELECT name, department, c_name, grade
FROM student, score
WHERE (name LIKE '张%' OR name LIKE '王%') AND student.id = score.stu_id;
```
7. **将student表的“计算机系”修改为“信息工程学院”**:
```sql
UPDATE student SET department = '信息工程学院' WHERE department = '计算机系';
```
8. **将学号为“902”的学生的计算机成绩加10分**:
```sql
UPDATE score SET grade = grade + 10 WHERE stu_id = '902' AND c_name = N'计算机';
```
9. **删除score表中计算机课程的成绩信息**:
```sql
DELETE FROM score WHERE c_name = N'计算机';
```
阅读全文