0
對於每個site_id
我有,以確定是否plan_id
在過去1
(過去就意味着較小id
)和不1
在此之前的一些點,例如:如何在Redshift中執行此查詢?
create table billing (id int, site_id int, plan_id int);
insert into billing values
(40301, 1, 1), (40302, 1, 16), (40304, 1, 15),
(40401, 2, 1), (40402, 2, 16), (40403, 2, 1), (40404, 2, 15);
應返回:
site_id = 1, did_return = false
site_id = 2, did_return = true
給定site_id
的billing
記錄的數量可能爲1或幾十。
我曾嘗試嵌套查詢:
select (
select (
select id from billing where plan_id <> 1 and id < b2.id order by id desc limit 1
)
from billing b2 where plan_id = 1 and id < b1.id order by id desc limit 1
)
from billing b1
order by id desc limit 1
但紅移不支持這種類型的查詢:
ERROR: This type of correlated subquery pattern is not supported due to internal error
是否有另一種方式做到這一點? Redshift與Postgres類似,因此也可能有postgres的答案。