ソースコード
-- 追加
with added as (
select item_code from item 
except 
select item_code from item_history
)

-- 削除
, deleted as (
select item_code from item_history
except 
select item_code from item 
)

-- 更新, 追加分を除外する必要あり
, updated as (
select item_code, user_update_datetime from item
where item_code not in (select item_code from added)
except 
select item_code, user_update_datetime from item_history
)
, all_ as (
select 
  item_code as CODE 
  ,item_name as NAME 
  ,'ADDED' as COMP_RSLT
from item 
where item_code in (select item_code from added)
union 
select 
  item_code as CODE 
  ,item_name as NAME 
  ,'DELETED' as COMP_RSLT
from item_history
where item_code in (select item_code from deleted)
union
select 
  item_code as CODE 
  ,item_name as NAME 
  ,'UPDATED' as COMP_RSLT
from item
where item_code in (select item_code from updated)
)
select *
from all_
order by CODE desc
;
提出情報
提出日時2024/04/22 11:27:37
コンテスト第12回 SQLコンテスト
問題データ操作履歴
受験者hattsuriboy
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量98 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
83 MB
データパターン2
AC
83 MB
データパターン3
AC
98 MB