Say that I have a time based dataset, which contains an array of data like this:
{
"group": "a", "date": "2017/01/01", value: 0.01
},
{
"group": "a", "date": "2017/01/02", value: 0.02
}
How can I produce a result set like this:
{
"group": "a", value_sum: 0.03, timeline: [["2017/01/01", 0.01], ["2017/01/02", 0.02]]
}
and so on.
I'm using Eloquent ORM, and I'm currently stick to a pattern where I make two different queries, the first to get the sum for each distinct group:
SELECT group, sum(value) FROM table GROUP BY group
and the second one to get the trends:
SELECT group, date, sum(value) FROM table GROUP BY group, date
then I merge the two results set in php.
I'm looking for a way to get all results in one query