ソースコード
WITH
---2023年7月当該顧客1件目の受注
wk_custfirst7(ORDER_NO, ORDER_DATETIME, MEMBER_CODE)
AS
 (
 SELECT
  MIN(ORDER_NO) as ORDER_NO
  ,MIN(date(ORDER_DATETIME)) as ORDER_DATETIME
  ,MEMBER_CODE
 FROM
  EC_ORDERS
 WHERE
  ORDER_DATETIME >= '2023-07-01' and ORDER_DATETIME < '2023-08-01'
 GROUP BY
  MEMBER_CODE
 )
,
---1つ前の受注
wk_custpre(ORDER_NO, ORDER_DATETIME, MEMBER_CODE)
AS
 (
 SELECT
  MAX(a.ORDER_NO) as ORDER_NO
  ,MAX(date(a.ORDER_DATETIME)) as ORDER_DATETIME
  ,a.MEMBER_CODE
 FROM
  EC_ORDERS a
  left outer join
  wk_custfirst7 b
  on
   a.MEMBER_CODE = b.MEMBER_CODE
 WHERE
   a.ORDER_DATETIME < b.ORDER_DATETIME
 GROUP BY
  a.MEMBER_CODE
 )

SELECT
 y.ORDER_DATETIME as ORDER_DATE
 ,x.MEMBER_CODE as CODE
 ,(case when m.OPTOUT_TYPE=0 then '可'  when m.OPTOUT_TYPE=1 then '不可' else '不明' end) as OPTOUT
FROM
 EC_ORDERS x
 inner join
 wk_custfirst7 y
 on
  x.MEMBER_CODE = y.MEMBER_CODE
 inner join
 wk_custpre z
 on
  x.MEMBER_CODE = z.MEMBER_CODE
 inner join
 MEMBER_MST m
 on
  x.MEMBER_CODE = m.MEMBER_CODE
WHERE
 date(y.ORDER_DATETIME, '+1 year') > z.ORDER_DATETIME
ORDER BY
 x.ORDER_DATETIME desc
 ,x.MEMBER_CODE desc

提出情報
提出日時2023/10/13 14:24:04
コンテスト第9回 SQLコンテスト
問題クーポン配布対象
受験者na1216
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量80 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
80 MB
データパターン2
WA
80 MB