解答

134

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_rev
FROM
  master
  LEFT JOIN sample.customers
  USING
    (user_id)
WHERE
  gender = 1
ORDER BY
  sum_rev DESC
LIMIT 1

結果テーブル

結果テーブル

サポートページに戻る