解答

153

SQL文(クエリ)

WITH master17 AS (
  SELECT
    user_id
  FROM
    sample.sales
  WHERE
    FORMAT_DATETIME("%Y", date_time) = "2017"
)
, master18 AS (
  SELECT
    user_id
  FROM
    sample.sales
  WHERE
    FORMAT_DATETIME("%Y", date_time) = "2018"
)
, master19 AS (
  SELECT
    user_id
  FROM
    sample.sales
  WHERE
    FORMAT_DATETIME("%Y", date_time) = "2019"
)
, master AS (
  SELECT
    user_id
  FROM
    master17
  INTERSECT DISTINCT
  SELECT
    user_id
  FROM
    master18
  INTERSECT DISTINCT
  SELECT
    user_id
  FROM
    master19
)
SELECT
  name
FROM
  master
  LEFT JOIN sample.customers
  USING
    (user_id)
ORDER BY
  birthday DESC
LIMIT 3

結果テーブル

結果テーブル

サポートページに戻る