Basic Join Part 2
CoddyのSQLジャーニー「基礎」セクションの一部。レッスン 44/72。
結合(Join)は、私たちが作成するテーブルに対しても使用できます。入れ子になったクエリ(サブクエリ)を結合で組み合わせるには、AS を追加して、その入れ子になったクエリに名前を識別できるようにする必要があります。
例えば以下のようになります:
SELECT table1.col1, table2.col2, ...
FROM table1, (SELECT * FROM table) AS table2
WHERE table1.id = table2.idチャレンジ
簡単利用可能なテーブルと列:
<strong>grades</strong>:<strong>course_id</strong>,<strong>student_id</strong>,<strong>grade</strong><strong>students</strong>:<strong>id</strong>,<strong>name</strong>
各生徒の平均成績を計算し、それぞれの名前と平均成績を返してください。
列名は student、grade としてください。
平均値は小数第2位に四捨五入(丸め)し、結果を平均成績の昇順で並べ替えてください。
自分で試してみよう
-- タスクが求めるように名前を変更した2つの出力列でこのリストを埋める
SELECT ____
FROM students,
(
-- これらの括弧内で、人ごとに丸めた平均を1つ生成する
SELECT student_id, ____
FROM grades
GROUP BY student_id
) AS avg_grades
-- 次に、共有のid列で内側の結果を外側のテーブルに照合する
WHERE ____
ORDER BY gradeこのレッスンには短いクイズがあります。レッスンを始めて解答し、進捗を記録しましょう。
基礎のすべてのレッスン
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns自分で練習してみよう: SQLプレイグラウンド