【发布时间】:2019-08-20 19:53:21
【问题描述】:
我有一个由多个子查询组成的查询。我使用'join',因为我不允许使用'with'。子查询有 'from' 子句,这会产生问题。
我必须显示两列,每列包含要显示的某些逻辑。为了打印这两列,我需要使用需要“from”子句的子查询。我不确定如何编写“from”子句以适应整个查询并使其可运行。我检查了各个查询,它们都工作正常。
select lead(dt) over
(partition by t1.id_user order by f.topup_date desc rows between 0
preceding and unbounded following )
from
(select *,
(max(case when f.topup_value >= 20 then f.topup_date end) over (partition
by f.id_user order by f.topup_date desc rows between 0 preceding and
unbounded following )) as dt
from topups f) as f, //(<-I think this is incorrect)
CAST(f.topup_value as float)/CAST(t1.topup_value as float) from
(SELECT t1.seq,t1.id_user,t1.topup_value,row_number()
over (partition by t1.id_user order by t1.topup_date )
as rowrank from topups t1) as t1
inner join topups f on f.id_user=t1.id_user
inner join topups t2 on t1.seq=t2.seq
【问题讨论】:
-
如果“个人查询”有效,您可以发布它们和一些示例数据,以及预期的输出吗?为什么不能使用
WITH?
标签: sql postgresql window-functions