Created
September 12, 2025 13:27
-
-
Save Alextrapixel/a176814c57de0ee05857777711efe551 to your computer and use it in GitHub Desktop.
Revisions
-
Alextrapixel created this gist
Sep 12, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ If your table has: | name | small | big | |:---|:---:|:---:| | apple | 10 | 20| | banana | 5 | 15 | We can make this query: ```sql SELECT name, JSON_ARRAY( JSON_OBJECT('size', 'small', 'quantity', small), JSON_OBJECT('size', 'big', 'quantity', big) ) AS detail FROM your_table; ``` And the query will return: | name | detail | |---|---| | apple | `[{"size": "small", "quantity": 10}, {"size": "big", "quantity": 20}]` | | banana | `[{"size": "small", "quantity": 5}, {"size": "big", "quantity": 15}]` |