解答

191

SQL文(クエリ)

WITH master AS (
  SELECT
    user_id
    , SUM(revenue) AS sum_rev
  FROM
    sample.sales
  GROUP BY
    user_id
)
SELECT
  gender_name
  , MAX(sum_rev) AS max_sum_rev
FROM
  (
    SELECT
      CASE gender
        WHEN 1 THEN "男性"
        WHEN 2 THEN "女性"
        ELSE "不明"
      END AS gender_name
      , sum_rev
    FROM
      master
      LEFT JOIN sample.customers
      USING
        (user_id)
  )
GROUP BY
  gender_name

結果テーブル

結果テーブル

サポートページに戻る