解答

139

SQL文(クエリ)

WITH master AS (
  SELECT
    user_id
    , SUM(revenue) AS sum_rev
    , SUM(quantity) AS sum_qty
  FROM
    sample.sales
  GROUP BY
    user_id
)
SELECT
  prefecture
  , SUM(sum_rev) / SUM(sum_qty) AS avg_unit_price
FROM
  master
  JOIN sample.customers
  USING
    (user_id)
GROUP BY
  prefecture
ORDER BY
  avg_unit_price DESC
LIMIT 3

結果テーブル

結果テーブル

サポートページに戻る