查询没有挂科的同学,显示班级,学号,姓名,生日,按照班级,学号升序进行排序
时间: 2023-12-10 22:02:21 浏览: 43
好的,你可以使用以下 SQL 语句来查询没有挂科的同学,并按照班级,学号升序进行排序:
```
SELECT
student.class AS 班级,
student.id AS 学号,
student.name AS 姓名,
student.birthday AS 生日
FROM
student
WHERE
NOT EXISTS (
SELECT
1
FROM
score
WHERE
score.student_id = student.id AND score.score < 60
)
ORDER BY
student.class ASC, student.id ASC;
```
注:此处假设有两个表,一个是学生表 "student",包含了班级、学号、姓名和生日等信息;另一个是成绩表 "score",包含了学生的学号、科目和成绩等信息。以上 SQL 语句就是查询出没有挂科的同学。
相关问题
mysql编写查询指定班级的所有同学信息,并按学号升序排列
可以使用以下 SQL 语句查询指定班级的所有同学信息,并按照学号升序排列:
```
SELECT * FROM students WHERE class='指定班级' ORDER BY student_id ASC;
```
其中,`students` 为学生表的表名,`class` 为班级名字段,`student_id` 为学号字段。在 `WHERE` 子句中指定 `class` 为指定班级的名称,使用 `ORDER BY` 子句按照 `student_id` 字段进行升序排列。
并按照考试成绩降序和学号升序排序
要按照考试成绩降序和学号升序对表进行排序,可以使用SQL语句中的ORDER BY子句。假设有一个名为"students"的表,包含字段"学号"(student_id)和"考试成绩"(exam_score),可以按照以下方式编写SQL查询语句:
```sql
SELECT * FROM students
ORDER BY exam_score DESC, student_id ASC;
```
上述语句中,"DESC"表示降序排序,"ASC"表示升序排序。首先根据"exam_score"字段进行降序排序,然后在考试成绩相同时,按照"student_id"字段进行升序排序。
执行以上SQL查询语句后,将返回按照考试成绩降序和学号升序排序的结果集。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)