本文介绍了N1QL将许多子行连接为单个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑到Couchbase,我有一个人员数据库,其中包含3个文档:
Consider in Couchbase I have a person database, with 3 documents:
Person A
Child AA
Grand AAA
Grand AAB
Child AB
Grand ABA
Grand ABB
Person B
Person C
Child CA
Child CB
Grand CBA
是否有一种简单的方法可以使用N1QL将其转换为以下结果?我正在尝试将每个人和他们的大孩子展示成字符串吗?
Is there an easy way to turn this into following results using N1QL?I am trying to display each person with their grand children displayed into strings?
Person A, Grand: "AAA, AAB, ABA, ABB"
Person B, Grand: ""
Person C, Grand: "CBA"
推荐答案
您可以执行以下操作:
SELECT p.name AS p, ENCODE_JSON(ARRAY_AGG(g.name)) AS g
FROM person AS p LEFT OUTER UNNEST p.child AS c LEFT OUTER UNNEST c.grand AS g
GROUP BY p;
这篇关于N1QL将许多子行连接为单个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!