同じ日付の複数の値があるため、同じ日付の複数の日付があり、日付をグループ化してtime
とbg_reading
という配列があります。これが私のJSONが吐き出すものです。JSONとして出力するときにデータベースの列を配列にグループ化できますか?
`[
{
"date": "2016-03-18T00:00:00.000Z",
"time": ["05:22:33", "09:33:10", "15:01:34", "18:03:34", "21:34:09"],
"bg_reading": [9.4, 6.3, 13.3, 6.8, 7.3]
}...
]`
しかし、一体は非常に多くの繰り返し値が存在すると、なぜ複数の日付があるなぜ、今、私は見当がつかない:
`[
{
"date": "2016-03-18T00:00:00.000Z",
"time": "22:03:54",
"bg_reading": 9.4
},
{
"date": "2016-03-19T00:00:00.000Z",
"time": "12:05:56",
"bg_reading": 12.4
},
{
"date": "2016-03-20T00:00:00.000Z",
"time": "01:17:06",
"bg_reading": 15.5
},
{
"date": "2016-03-21T00:00:00.000Z",
"time": "06:27:42",
"bg_reading": 17.1
},
{
"date": "2016-03-22T00:00:00.000Z",
"time": "06:19:21",
"bg_reading": 27.6
},
{
"date": "2016-03-22T00:00:00.000Z",
"time": "17:03:27",
"bg_reading": 14.5
},
{
"date": "2016-03-18T00:00:00.000Z",
"time": "22:03:54",
"bg_reading": 9.4
},
{
"date": "2016-03-19T00:00:00.000Z",
"time": "12:05:56",
"bg_reading": 12.4
},
{
"date": "2016-03-20T00:00:00.000Z",
"time": "01:17:06",
"bg_reading": 15.5
},
{
"date": "2016-03-21T00:00:00.000Z",
"time": "06:27:42",
"bg_reading": 17.1
},
{
"date": "2016-03-22T00:00:00.000Z",
"time": "06:19:21",
"bg_reading": 27.6
},
{
"date": "2016-03-22T00:00:00.000Z",
"time": "17:03:27",
"bg_reading": 14.5
},
{
"date": "2016-03-18T00:00:00.000Z",
"time": "22:03:54",
"bg_reading": 9.4
},
{
"date": "2016-03-19T00:00:00.000Z",
"time": "12:05:56",
"bg_reading": 12.4
},
{
"date": "2016-03-20T00:00:00.000Z",
"time": "01:17:06",
"bg_reading": 15.5
},
{
"date": "2016-03-21T00:00:00.000Z",
"time": "06:27:42",
"bg_reading": 17.1
},
{
"date": "2016-03-22T00:00:00.000Z",
"time": "06:19:21",
"bg_reading": 27.6
},
{enter code here
"date": "2016-03-22T00:00:00.000Z",
"time": "17:03:27",
"bg_reading": 14.5
}
]`
私はこのようなこと何かを持って期待していました。これが私がSequeliseでそれを照会しようとした方法です。
` Log.findAll({
where: {
bg_reading: {gt: 0}
},
attributes: ['date', 'time', 'bg_reading'],
group: 'date',
})
.then(function(data) {
res.send(data)
})
`