我正在使用Vertica SQL,并有以下表。
CREATE temp TABLE XXX (DATE TEXT, PRICE INTEGER);
INSERT INTO XXX VALUES
('2019-04-27 01:00', 1), ('2019-04-27 02:30', 3), ('2019-04-27 18:00',2),
('2019-04-28 17:00', 2), ('2019-04-28 21:00', 5),
('2019-04-29 17:00',50), ('2019-04-29 21:00',10),
('2019-04-30 17:00',10), ('2019-04-30 21:00',20),
('2019-05-01 17:00',40), ('2019-05-01 21:00',10),
('2019-05-02 17:00',10), ('2019-05-02 21:00', 6);
我想在表中找到今天和日期之间的差异(以天为单位计算)。
select (date_trunc('month',DATE)-date_trunc('month',current_date)) as DATE, PRICE from XXX
据我所知,初始表有13行,但是date_trunc('month',current_date)有1行。结果我出现了一个错误。如何解决这个问题?
由于我使用Vertica,我应该在标签中添加PostgreSQL或MySQL吗?
试着用任一 datediff
或 timestampdiff
datediff('day', date , Now()) as DaysBetweenDates
timestampdiff(day, date, Now()) as DaysBetweenDates