我只是在寻找有关json答案的帮助。
当我在postgres数据库上使用查询时,得到以下结果:
select sum(total_value), CAST(date_start AS DATE)
from result
where DATE(date_start) BETWEEN '2019-07-11' AND '2019-07-18'
group by CAST(date_start AS DATE)
order by CAST(date_start AS DATE);
"16.81" "2019-07-11"
"15.42" "2019-07-12"
"40.08" "2019-07-15"
"11.45" "2019-07-16"
"91.52" "2019-07-17"
"25.34" "2019-07-18"
但是,如果我尝试使用pg模块的nodejs:
app.get('/getData', function(req, res) {
var date = new Date()
var lastWeek = new Date();
lastWeek.setDate(lastWeek.getDate()-7)
date1 = date.getFullYear() +"-"+ (date.getMonth()+1) +"-"+ date.getDate()
date2 = lastWeek.getFullYear() +"-"+ (lastWeek.getMonth()+1) +"-"+ lastWeek.getDate()
console.log(date1, date2)
pool.query('select sum(total_value), CAST(date_start AS DATE) from result where DATE(date_start) BETWEEN '2019-07-11' AND '2019-07-18' GROUP BY CAST(date_start AS DATE) ORDER BY CAST(date_start AS DATE)',
(error, results) => {
if (error) {
throw error
}
res.status(200).json(results.rows)
})
})
我得到了这个JSON答案:
[{"sum":"16.81","date_start":"2019-07-10T22:00:00.000Z"},
{"sum":"15.42","date_start":"2019-07-11T22:00:00.000Z"},
{"sum":"40.08","date_start":"2019-07-14T22:00:00.000Z"},
{"sum":"11.45","date_start":"2019-07-15T22:00:00.000Z"},
{"sum":"91.52","date_start":"2019-07-16T22:00:00.000Z"},
{"sum":"25.34","date_start":"2019-07-17T22:00:00.000Z"}]
为什么我的日子不一样?