为什么我的临时表不会填充数据,但其中的select语句会填充



我遇到了一个问题,这个问题对我来说是一个巨大的障碍。我似乎无法理解这个问题,我希望有人能帮我提供一些指导。

所以我的问题是当我创建临时表时,我做

select * from all_subs

我有一张空桌子。然而,当我测试运行包含临时表的select语句时,我会得到结果。。。我的查询看起来像这个

drop table if exists all_subs;
select sdb.id as subscription_id,
sdb.created_at,
sdb.user_id as user_id,
sdb.is_gift as is_gift,
case when pl.sku like '%auto-cancel%' then 1 else 0 end as is_auto_cancel,
sdb.current_period_ends_at as current_period_ends_at,
sdb.expires_at as expires_at,
sdb.current_period_started_at as current_period_started_at,
case when sdb.expires_at is null then 0 else 1 end as expiring,
case when pl.sku ilike '%mobi1' then 1
when pl.sku ilike '%mobi6' then 6
when pl.sku ilike '%mobi12' then 12
else pl.duration end as duration,
sdb.dog_name as dog_name,
sdb.dog_birthday as dog_birthday,
pl.sku as sku,
cast(round(100.0 * pl.price, 0) as int) as price,
cast(round(100.0 * pl.price / pl.duration, 0) as int) as mrr,
case
when sdb.expires_at is null and getdate() between sdb.current_period_started_at and sdb.current_period_ends_at  then 'active'
when sdb.expires_at > getdate() then 'canceled'
when sdb.expires_at <= getdate() or (sdb.expires_at is null and sdb.current_period_ends_at < date_add('day',-30,getdate())) then 'expired'
else 'unknown'
end as subscription_state,
coalesce(can.no_new_products, false) as no_new_products,
coalesce(can.dog_did_not_like, false) as dog_did_not_like,
coalesce(can.not_enough_value, false) as not_enough_value,
coalesce(can.dog_died, false) as dog_died,
coalesce(can.cant_afford, false) as cant_afford,
coalesce(can.offer_accepted, false) as offer_accepted,
coalesce(can.too_big_too_small, false) as too_big_too_small,
coalesce(can.allergies, false) as allergies,
coalesce(can.too_much_treats, false) as too_much_treats,
coalesce(can.too_few_toys, false) as too_few_toys,
coalesce(can.toy_durability, false) as toy_durability,
coalesce(can.new_address, false) as new_address,
coalesce(can.something_different, false) as something_different,
case when ais.subscription_id is not null then 1 else 0 end add_item,
case when eets.subscription_id is not null then 1 else 0 end ever_extra_toy,
case when  sdb.allergies = '{""}' then 0
when sdb.allergies is null then 0
else 1 end as is_allergy,
min(s.shipped_at) first_box_shipped_at,
count(distinct case when s.shipped_at is not null then o.id end) shipped_orders,
cast((case when (sdb.expires_at <= getdate() or (sdb.expires_at is null and sdb.current_period_ends_at < date_add('day',-30,getdate())))
and count(distinct case when s.shipped_at is not null then o.id end) = 0 then 1 else 0 end) as boolean) is_killed
into temp all_subs
from subscriptions as sdb
left join subscription_cancellation_summary as can on can.subscription_id = sdb.id
left join plans as pl on pl.id = sdb.current_plan_id
left join add_item_subs ais on ais.subscription_id = sdb.id
left join ever_extra_toy_subs eets on eets.subscription_id = sdb.id
left join orders  o on o.orderable_type = 'Subscription' and o.orderable_id = sdb.id
left join orders_shipments os on os.order_id = o.id
left join shipments s on s.id = os.shipment_id
left join common.subs_dim sd on sd.subscription_id = sdb.id
where
-- Only valid subscriptions
sd.is_killed = false
group by sdb.id,
sdb.created_at,
sdb.user_id,
sdb.is_gift,
case when pl.sku like '%auto-cancel%' then 1 else 0 end,
sdb.current_period_ends_at,
sdb.expires_at,
sdb.current_period_started_at,
case when sdb.expires_at is null then 0 else 1 end,
case when pl.sku ilike '%mobi1' then 1
when pl.sku ilike '%mobi6' then 6
when pl.sku ilike '%mobi12' then 12
else pl.duration end,
sdb.dog_name,
sdb.dog_birthday,
pl.sku,
cast(round(100.0 * pl.price, 0) as int),
cast(round(100.0 * pl.price / pl.duration, 0) as int),
case
when sdb.expires_at is null and getdate() between sdb.current_period_started_at and sdb.current_period_ends_at  then 'active'
when sdb.expires_at > getdate() then 'canceled'
when sdb.expires_at <= getdate() or (sdb.expires_at is null and sdb.current_period_ends_at < date_add('day',-30,getdate())) then 'expired'
else 'unknown'
end,
coalesce(can.no_new_products, false),
coalesce(can.dog_did_not_like, false),
coalesce(can.not_enough_value, false),
coalesce(can.dog_died, false),
coalesce(can.cant_afford, false),
coalesce(can.offer_accepted, false),
coalesce(can.too_big_too_small, false),
coalesce(can.allergies, false),
coalesce(can.too_much_treats, false),
coalesce(can.too_few_toys, false),
coalesce(can.toy_durability, false),
coalesce(can.new_address, false),
coalesce(can.something_different, false),
case when ais.subscription_id is not null then 1 else 0 end,
case when eets.subscription_id is not null then 1 else 0 end,
case when  sdb.allergies = '{""}' then 0
when sdb.allergies is null then 0
else 1 end;

有人遇到这个问题吗?请帮忙!提前非常感谢

尝试更改

into temp all_subs

INTO TEMP TABLE all_subs

最新更新