我有以下格式的表格 -
orderNumber | orderName
-------------+------------
1 | Pizza
1 | Pasta
使用 SQL 查询,我期待以下格式的输出 -
{
"data": [{
"orderNumber":1,
"orders": [
{"orderName": "Pizza"},
{"orderName": "Pasta"}
]
}]
}
但我的实际输出格式如下 -
{
"data": [
{
"orderNumber": 1,
"orders" [
{"orderName": "Pizza"}
]
},
{
"orderNumber": 1,
"orders": [
{"orderName": "Pasta"}
]
}
]
}
我正在使用的 SQL 查询是 -
SELECT
(SELECT orderNumber as orderNumber,
(SELECT orderName
FROM sample_table b
WHERE a.orderNumber = b.orderNumber
FOR JSON PATH) AS orders
FROM sample_table a FOR JSON PATH, ROOT('data')
) AS orderdata
谁能帮我吗?