解答

187

SQL文(クエリ)

SELECT
  COUNT(DISTINCT user_id) users
FROM
  (
    SELECT
      user_id
      , MAX(IF(product_id = 1, 1, 0)) AS product1_flag
      , MAX(IF(product_id = 2, 1, 0)) AS product2_flag
      , MAX(IF(product_id = 15, 1, 0)) AS product15_flag
    FROM
      sample.sales
    GROUP BY
      user_id
    HAVING product1_flag > 0
  AND product2_flag > 0
  AND product15_flag = 0
  )

結果テーブル

結果テーブル

サポートページに戻る