解答

140

SQL文(クエリ)

SELECT
  CASE
    WHEN prefecture IN("東京", "千葉", "埼玉", "神奈川") THEN "東京圏"
    WHEN prefecture IN("大阪", "奈良", "兵庫", "京都") THEN "大阪圏"
    ELSE NULL
  END AS area
  , SUM(revenue) AS sum_rev
FROM
  sample.sales
  LEFT JOIN sample.customers
  USING
    (user_id)
GROUP BY
  area
HAVING area IS NOT NULL
ORDER BY
  sum_rev DESC

結果テーブル

結果テーブル

サポートページに戻る