-
Notifications
You must be signed in to change notification settings - Fork 664
How to add own keys for grouped output
agershun edited this page Dec 28, 2014
·
1 revision
Source: StackOverflow.com
The raw data returned is this:
[
{
"name": "jim",
"color": "blue",
"age": "22"
},
{
"name": "Sam",
"color": "blue",
"age": "33"
},
{
"name": "eddie",
"color": "green",
"age": "77"
}
]
I want the "group by" function to return an object that looks like this:
[
{
color: "blue",
users: [
{
"name": "jim",
"color": "blue",
"age": "22"
},
{
"name": "Sam",
"color": "blue",
"age": "33"
}
]
},
{
color: "green",
users: [
{
"name": "eddie",
"color": "green",
"age": "77"
}
]
}
]
var res = alasql('SELECT color, ARRAY(_) AS users FROM ? GROUP BY color',[data]);
Try this example in jsFiddle
© 2014-2024, Andrey Gershun & Mathias Rangel Wulff
Please help improve the documentation by opening a PR on the wiki repo