ソースコード
SELECT
 SUB.ORDER_DATETIME AS ORDER_DATE,
 SUB.MEMBER_CODE AS CODE,
 CASE MM.OPTOUT_TYPE
  WHEN 0 THEN '可'
  WHEN 1 THEN '不可'
  ELSE '不明'
  END AS OPTOUT

FROM
 (
 SELECT
  MEMBER_CODE,
  LAST_NAME,
  FIRST_NAME,
  MIN(ORDER_DATETIME) AS ORDER_DATETIME,
  MIN(DATE (ORDER_DATETIME)) AS M_DATE
 FROM
  EC_ORDERS
 WHERE
  DATE (ORDER_DATETIME) BETWEEN '2023-07-01' AND '2023-07-31'
 GROUP BY MEMBER_CODE
 ) AS SUB
 
 INNER JOIN MEMBER_MST AS MM
  ON SUB.MEMBER_CODE = MM.MEMBER_CODE
  
WHERE
 EXISTS(
  SELECT
   ORDER_NO
  FROM
   EC_ORDERS
  WHERE
   SUB.MEMBER_CODE = MEMBER_CODE
   AND DATE (ORDER_DATETIME) < DATE (SUB.M_DATE, '-1 year')
  )
  AND NOT EXISTS(
  SELECT
   ORDER_NO
  FROM
   EC_ORDERS
  WHERE
   SUB.MEMBER_CODE = MEMBER_CODE
   AND DATE (ORDER_DATETIME) BETWEEN DATE(SUB.M_DATE, '-1 year') AND DATE(SUB.M_DATE, '-1 day')
  )

ORDER BY 
 SUB.ORDER_DATETIME DESC,
 SUB.MEMBER_CODE DESC;
  
   
   
  
  
  
  
 
提出情報
提出日時2024/08/28 10:23:25
コンテスト第9回 SQLコンテスト
問題クーポン配布対象
受験者tatataka
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量84 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
84 MB