解答

141

SQL文(クエリ)

WITH master AS (
  SELECT
    user_id
    , SUM(revenue) AS sum_rev
  FROM
    sample.sales
  GROUP BY
    user_id
)
SELECT
  DATE_DIFF("2019-12-31", birthday, YEAR) AS age
  , SUM(sum_rev) AS sum_rev
FROM
  master
  LEFT JOIN sample.customers
  USING
    (user_id)
GROUP BY
  age
HAVING age IS NOT NULL
ORDER BY
  sum_rev DESC
LIMIT 3

結果テーブル

結果テーブル

サポートページに戻る