I would like to ask you for advice as I don’t know which method to use:
For example with this query in Mysql i have this table:
user_Id | name | age | photo |
---|---|---|---|
1 | Zack | 23 | Blob[2.1] |
1 | Zack | 23 | Blob[3.3] |
1 | Zack | 23 | Blob[1.9] |
3 | Amy | 19 | Blob[2.9] |
3 | Amy | 19 | Blob[3.3] |
In node js when i transform it in a Json file i have 5 rows, but i want 2 rows with the grouped photos. Example:
{
"0": {
"user_id": 1,
"name": "Zack",
"age": 23,
"photo": [
"Blob[2.1]",
"Blob[3.3]",
"Blob[1.9]"
]
},
"1": {
"user_id": 2,
"name": "Amy",
"age": 19,
"photo": [
"Blob[2.9]",
"Blob[3.3]"
]
}
}
So, do I have to use some function in nodejs or do I have to add something in mysql query?
2
Answers
You need to aggregate then photo values
Query #1
View on DB Fiddle
You can generate row indexes as aggregating photo reference values, and then aggregate the resultant individual objects with keys derived from those indexes such as
Demo