Recap - Self Join
CoddyのSQLジャーニー「基礎」セクションの一部 — レッスン 47/72。
チャレンジ
難しい利用可能なテーブルと列:
<strong>friends</strong>:<strong>id</strong>,<strong>name</strong>,<strong>friend_id</strong>
friends テーブル内の各人物について、彼らが持つすべての友達の友達のつながりを見つけます。友達の友達のつながりとは、人物 A が人物 B と友達で、その B がさらに人物 C と友達である場合に発生します。これらのつながりを 3 つの列としてリストします:
- friend1: 起点となる人物
- friend2: 直接の友人
- friend3: 友人の友人
ルール:
- friend3 が friend1 と同じ人物の場合を含めない
- friend1 の名前で降順に結果を並べ替える
例:Alice が Bob と友達で、Bob が Carol と友達の場合、Alice-Bob-Carol は有効な友達の友達のつながりとなります。
自分で試してみよう
基礎のすべてのレッスン
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