解答

144

SQL文(クエリ)

WITH master AS (
  SELECT
    user_id
    , product_id
    , SUM(revenue) AS sum_rev
  FROM
    sample.sales
  GROUP BY
    user_id
    , product_id
)
SELECT
  product_id
  , SUM(sum_rev) AS sum_rev
FROM
  master
  JOIN sample.customers
  USING
    (user_id)
WHERE
  DATE_DIFF("2019-12-31", birthday, YEAR) >= 50
GROUP BY
  product_id
ORDER BY
  sum_rev DESC
LIMIT 3

結果テーブル

結果テーブル

サポートページに戻る