ソースコード
with member_202307 as (
    select 
        MEMBER_CODE
    from 
        EC_ORDERS
    where
        date(ORDER_DATETIME) between '2023-07-01' and '2023-07-31'
    group by 
        MEMBER_CODE
)
select
    min(ORDER_DATETIME) as ORDER_DATE
    , o.MEMBER_CODE as CODE
    , case
        when OPTOUT_TYPE = 0 then '可'
        when OPTOUT_TYPE = 1 then '不可'
        else '不明' end as OPTOUT
from (
    select
        ORDER_DATETIME
        , lag(ORDER_DATETIME, 1) over(partition by MEMBER_CODE order by ORDER_DATETIME) as ORDER_DATETIME_lag
        , MEMBER_CODE
    from EC_ORDERS
    )o
    inner join
        member_202307 m
        on o.MEMBER_CODE = m.MEMBER_CODE
    left outer join 
        MEMBER_MST mm
        on o.MEMBER_CODE = mm.MEMBER_CODE
where
    date(ORDER_DATETIME, '-1 year') > ORDER_DATETIME_lag
group by 
    o.MEMBER_CODE
order by 
    ORDER_DATETIME desc
    , CODE desc
提出情報
提出日時2024/02/11 23:35:22
コンテスト第9回 SQLコンテスト
問題クーポン配布対象
受験者ryatora
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
AC
85 MB