Kodewick
開始學 →
基礎←→0 / 70

起個短名字

#041基礎JOIN + AS約 4 分鐘

成績單要列出每條成績。把 students 和 scores 連起來(scores.student_id = students.id),按順序選出 name、subject、score。表名太長?可以給表起個短名字。

用到的表
students
  • idPK
  • name
  • class
  • age
  • city
scores
  • idPK
  • student_idFK
  • subject
  • score

scores.student_id → students.id

students
idnameclassagecity
1Amy1A12Leeds
2Ben1A13York
3Cara1B12NULL
4Dan1B14Leeds
5Eva1A12Hull
6Finn1C13NULL
7Gus1C12York
7 行
scores
idstudent_idsubjectscore
11math92
21art78
32math65
42art88
53math74
64math55
74art90
85math81
95artNULL
107math99
10 行
query.sql
-- 在這裡寫:用 AS 給兩張表起短名字,連起來選出 name、subject、score
SELECT name
FROM students;
Ctrl + Enter 也能執行
結果

寫好了先點「執行」看看結果,沒問題再點「提交」。