解答

154

SQL文(クエリ)

WITH product17 AS (
  SELECT
    product_id
  FROM
    sample.sales
  WHERE
    EXTRACT(YEAR FROM date_time) = 2017
  GROUP BY
    product_id
  HAVING SUM(revenue) >= 100000
)
, product18 AS (
  SELECT
    product_id
  FROM
    sample.sales
  WHERE
    EXTRACT(YEAR FROM date_time) = 2018
  GROUP BY
    product_id
  HAVING SUM(revenue) >= 200000
)
, product19 AS (
  SELECT
    product_id
  FROM
    sample.sales
  WHERE
    EXTRACT(YEAR FROM date_time) = 2019
  GROUP BY
    product_id
  HAVING SUM(revenue) <= 200000
)
SELECT
  *
FROM
  product17
INTERSECT DISTINCT
SELECT
  *
FROM
  product18
INTERSECT DISTINCT
SELECT
  *
FROM
  product19

結果テーブル

結果テーブル

サポートページに戻る