解答

148

SQL文(クエリ)

WITH master AS (
  SELECT
    user_id
    , COUNT(DISTINCT order_id) AS orders
  FROM
    sample.sales
  GROUP BY
    user_id
)
SELECT
  IF(gender = 1, "男性", "女性") AS gender
  , AVG(orders) AS avg_order
FROM
  master
  JOIN sample.customers
  USING
    (user_id)
GROUP BY
  gender

結果テーブル

結果テーブル

サポートページに戻る