描述
請編寫 SQL 語句,查詢課程表
courses
中課程名稱為
System Design
的課程資訊。
表定義:courses(課程表)
列名 | 類型 | 注釋 |
id | int | 主鍵 |
name | varchar | 課程名稱 |
student_count | 學生總數 | |
created_at | date | 開課時間 |
teacher_id | 講師 id |
**
如果查詢不到結果,就什麼都不傳回。
樣例
樣例一:
表内容:courses
1 | Advanced Algorithms | 880 | 2020-6-1 | 4 |
2 | System Design | 1350 | 2020-7-18 | 3 |
Django | 780 | 2020-2-29 | ||
Web | 340 | 2020-4-22 | ||
5 | Big Data | 700 | 2020-9-11 | |
6 | Artificial Intelligence | 1660 | 2018-5-13 | |
7 | Java P6+ | 2019-1-19 | ||
8 | Data Analysis | 500 | 2019-7-12 | |
10 | Object Oriented Design | 300 | 2020-8-8 | |
12 | Dynamic Programming | 2000 | 2018-8-18 |
在運作你的 SQL 語句之後,表應傳回:
樣例二:
樣例二中沒有符合條件的資料,是以輸出中隻包含表頭而沒有資料。
題解
這道題是一道入門級别的資料庫查詢題,建單的一個select即可成功。
這裡有個注意點是:postgresql的查詢條件WHERE name =‘System Design’;這裡用的是單引号,如果使用雙引号會報錯。
unterminated quoted identifier at or near "“System Design’;”
LINE 3: WHERE name ="System Design’;
MYSQL
SELECT id, name, student_count, created_at, teacher_id
FROM courses
WHERE name ="System Design";
• 1
• 2
• 3
Postgresql
SELECT id, name, student_count, created_at, teacher_id
FROM courses
WHERE name ='System Design';
• 1
• 2
• 3
• 4