解答

146

SQL文(クエリ)

WITH master AS (
  SELECT
    user_id
    , SUM(revenue) AS sum_rev
  FROM
    sample.sales
  GROUP BY
    user_id
)
SELECT
  FORMAT_DATE("%Y-%Q", IFNULL(register_date, DATE "2016-12-31")) AS register_quarter
  , SUM(sum_rev) AS sum_rev
FROM
  master
  LEFT JOIN sample.customers
  USING
    (user_id)
GROUP BY
  register_quarter
ORDER BY
  sum_rev DESC
LIMIT 3

結果テーブル

結果テーブル

サポートページに戻る