Menu
Coddy logo textTech

Recap - Join

CoddyのSQLジャーニー「基礎」セクションの一部。レッスン 45/72。

challenge icon

チャレンジ

中級

利用可能なテーブルとカラム:

  • <strong>orders</strong>: <strong>id</strong>, <strong>customer_id</strong>
  • <strong>products</strong>: <strong>id</strong>, <strong>unit_price</strong>, <strong>units_in_stock</strong>
  • <strong>order_items</strong>: <strong>id</strong>, <strong>order_id</strong>, <strong>product_id</strong>, <strong>quantity</strong>

unit_price10未満の商品を注文した顧客の顧客IDを取得し、各顧客が注文したそれらの安価な商品のquantityの合計を一覧表示してください。

以下のカラムを返してください:

  • customer_id
  • total_quantity (各顧客におけるunit_price < 10の商品の数量の合計)

自分で試してみよう

-- タスクが求めるグループ化列と集計値をリストする
SELECT ____
FROM orders
-- 各結合には、id列をそれを指す列に一致させる条件が必要です
INNER JOIN order_items ON ____
INNER JOIN products ON ____
-- 次に、タスクが説明するしきい値を満たす行のみを残す
WHERE ____
GROUP BY orders.customer_id;

基礎のすべてのレッスン

自分で練習してみよう: SQLプレイグラウンド