ソースコード
with T1 as (
    select MEMBER_CODE,min(ORDER_DATETIME) DT from EC_ORDERS where ORDER_DATETIME between '2023-07-00' and '2023-08-00' group by MEMBER_CODE
),
    T2 as (
        select distinct  EC.MEMBER_CODE  as memc from EC_ORDERS EC inner join T1 on EC.MEMBER_CODE=T1.MEMBER_CODE
                 where DATE(ORDER_DATETIME)>=DATE(T1.DT, '-1 year') and ORDER_DATETIME<T1.DT
    )
    select
        max(T1.DT) as ORDER_DATE,
        max(EC.MEMBER_CODE) as CODE,
        max(case when MEMBER_MST.OPTOUT_TYPE=0 then '可' when MEMBER_MST.OPTOUT_TYPE=1 then '不可' else '不明' end) as OPTOUT

        from EC_ORDERS EC inner join  T1 on EC.MEMBER_CODE=T1.MEMBER_CODE and ORDER_DATETIME<T1.DT
        inner join MEMBER_MST on EC.MEMBER_CODE=MEMBER_MST.MEMBER_CODE
    where DATE(ORDER_DATETIME)<DATE(T1.DT, '-1 year') and EC.MEMBER_CODE not in (select memc from T2)
    group by EC.MEMBER_CODE
order by 1 desc,2 desc
;


提出情報
提出日時2023/10/16 09:46:53
コンテスト第9回 SQLコンテスト
問題クーポン配布対象
受験者tamurakami
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量93 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
89 MB
データパターン2
AC
93 MB