我有以下查询。但是TranDate,Amount,Balance显示为Null。是Postgresql的新手。但是在sql服务器中,值正在显示
CREATE TEMP TABLE tran
(TranDate,Amount,Balance) AS
VALUES
('2019-01-01'::date, 1000::int,1000::int),
('2019-01-02', 2000,3000),
('2019-01-03', NULL,3000),
('2019-01-04', -500,2500);
SELECT tran.TranDate,tran.Amount,tran.Balance, date(d) as day
FROM generate_series(timestamp '2018-01-01'
, timestamp '2018-01-31'
, interval '1 day') d
left join tran ON date(tran.TranDate) = d
答案 0 :(得分:1)
如果使用重叠的日期范围运行代码,则会看到结果:
SELECT tran.TranDate, tran.Amount, tran.Balance, date(d) as day
FROM generate_series(timestamp '2019-01-01',
timestamp '2019-01-31',
interval '1 day'
) d left join
tran
ON date(tran.TranDate) = d ;
您可以在this db <>小提琴中观察到这一点。