ソースコード
with afterJulyOrder as(
select
	 MEMBER_CODE 
	,min(substr(ORDER_DATETIME,1,10)) as ORDER_DATE
	,min(ORDER_DATETIME) as ORDER_DATETIME
from
	EC_ORDERS
where
	substr(ORDER_DATETIME,1,10) between '2023-07-01' and '2023-07-31'
group by MEMBER_CODE
),
beforeJulyOrder as(
select
	 MEMBER_CODE 
	,max(substr(ORDER_DATETIME,1,10)) as ORDER_DATE
from
	EC_ORDERS
where
	substr(ORDER_DATETIME,1,10) < '2023-07-01'
group by MEMBER_CODE
)
select
	a.ORDER_DATETIME as ORDER_DATE, a.MEMBER_CODE as CODE,
	case 
		when m.OPTOUT_TYPE = '0' then '可'
		when m.OPTOUT_TYPE = '1' then '不可'
		else '不明'
	end as OPTOUT
from afterJulyOrder a
	inner join beforeJulyOrder b
	on  a.MEMBER_CODE = b.MEMBER_CODE
	and datetime(a.ORDER_DATE, '-1 years') > datetime(b.ORDER_DATE)
	inner join MEMBER_MST m
	on  a.MEMBER_CODE = m.MEMBER_CODE
order by
	a.ORDER_DATETIME desc, a.MEMBER_CODE desc
提出情報
提出日時2023/10/13 23:21:59
コンテスト第9回 SQLコンテスト
問題クーポン配布対象
受験者ckoga
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量78 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
78 MB
データパターン2
AC
78 MB