我有一个N1QL查询:
SELECT p.`ID`, p.`Name` FROM `Preferences` p WHERE `type` = "myType"
结果是对象列表[{"ID": "123", "Name": "John"}, ...]
我想获取结果JSON,例如:
{
"count": 5,
"result": [{"ID": "123", "Name": "John"}, ...]
}
如何使用N1QL做到这一点?
答案 0 :(得分:2)
SELECT
COUNT(t.ID) AS count,
ARRAY_AGG(t) AS results
FROM
(
SELECT
p.`ID`, p.`Name`
FROM
`Preferences` p
WHERE `type` = "myType"
) AS t