请编写 SQL 语句,查询课程表 courses
,对结果按照学生人数 student_count
进行升序排序。
表定义: courses (课程表)
列名 | 类型 | 注释 |
---|---|---|
id | int | 主键 |
name | varchar | 课程名称 |
student_count | int | 学生总数 |
created_at | date | 开课时间 |
teacher_id | int | 讲师 id |
样例一:
表内容 : courses
id | name | student_count | created_at | teacher_id |
---|---|---|---|---|
1 | Advanced Algorithms | 880 | 2020-6-1 | 4 |
2 | System Design | 1350 | 2020-7-18 | 3 |
3 | Django | 780 | 2020-2-29 | 3 |
4 | Web | 340 | 2020-4-22 | 4 |
5 | Big Data | 700 | 2020-9-11 | 1 |
6 | Artificial Intelligence | 1660 | 2018-5-13 | 3 |
7 | Java P6+ | 780 | 2019-1-19 | 3 |
8 | Data Analysis | 500 | 2019-7-12 | 1 |
10 | Object Oriented Design | 300 | 2020-8-8 | 4 |
12 | Dynamic Programming | 2000 | 2018-8-18 | 1 |
在运行你的 SQL 语句之后,表应返回:
id | name | student_count | created_at | teacher_id |
---|---|---|---|---|
10 | Object Oriented Design | 300 | 2020-8-8 | 4 |
4 | Web | 340 | 2020-4-22 | 4 |
8 | Data Analysis | 500 | 2019-7-12 | 1 |
5 | Big Data | 700 | 2020-9-11 | 1 |
3 | Django | 780 | 2020-2-29 | 3 |
7 | Java P6+ | 780 | 2019-1-19 | 3 |
1 | Advanced Algorithms | 880 | 2020-6-1 | 4 |
2 | System Design | 1350 | 2020-7-18 | 3 |
6 | Artificial Intelligence | 1660 | 2018-5-13 | 3 |
12 | Dynamic Programming | 2000 | 2018-8-18 | 1 |
样例二:
表内容 : courses
id | name | student_count | created_at | teacher_id |
---|---|---|---|---|
1 | Advanced Algorithms | 880 | 2020-6-1 | 4 |
2 | System Design | 1350 | 2020-7-18 | 3 |
3 | Django | 780 | 2020-2-29 | 3 |
在运行你的 SQL 语句之后,表应返回:
id | name | student_count | created_at | teacher_id |
---|---|---|---|---|
3 | Django | 780 | 2020-2-29 | 3 |
1 | Advanced Algorithms | 880 | 2020-6-1 | 4 |
2 | System Design | 1350 | 2020-7-18 | 3 |
本题主要考察order by的用法
SELECT * FROM courses ORDER BY student_count desc