gpt4 book ai didi

sql - Postgres SQL 多外连接生成时间序列

转载 作者:行者123 更新时间:2023-11-29 13:21:21 24 4
gpt4 key购买 nike

我正在尝试生成 future 48 个周期 x 天的系列,并在可用的情况下显示来自源表 (T1) 的匹配数据,但这看起来就像一个内部联接,并且只显示具有来自 T1 的匹配结果?

select
seq.date,
t1.date,
hh.period,
t1.period
From

myTable t1
right outer join (select date(date) from generate_series(current_date,current_date + '12 days'::interval ,'1 day'::interval) date)as seq
ON (seq.date= t1.date)
right outer join (select period from generate_series (1,48) period) hh
ON (hh.period = t1.period)

最佳答案

交叉加入系列,然后左加入表格

手机...

select seq.date, t1.date, hh.period, t1.period From (select date(date) 
from generate_series(current_date,current_date + '12 days'::interval ,'1 day'::interval) date)as seq
cross join (select period from generate_series (1,48) period) hh
Left join my table
ON (hh.period = t1.period)
And (seq.date= t1.date)

关于sql - Postgres SQL 多外连接生成时间序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41211136/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com