How to get multiple array value using N1Ql couchbase query?

Hi, I need a help. I am unable to get “t_name.name” value from following document
{
“_rev”: “1-98850503ade89466c843dbbe8d2199c5”,
“_id”: “febaad09-ee40-4cee-b24e-6ac03ac8198a”
“t_items”: [
{
“itemId”: “edaaad09-ee40-4cee-b24e-6ac03ac8198a”,
“name”: “baby shop-l”,
“priceVariations”: [
{
“price”: “12”,
“sku”: “adssd”,
“variationId”: null,
“variationName”: “Regular”
},
{
“price”: “24”,
“sku”: “df”,
“variationId”: null,
“variationName”: “l”
}
],
“selecteQty”: 2,
“selectedPrice”: “48.00”,
“selectedVariation”: {
“price”: “24”,
“sku”: “df”,
“variationId”: null,
“variationName”: “l”
},
“type”: “ITEM”
},
{
“itemId”: “exaaad09-ee40-4cee-b24e-6ac03ac8198a”,
“name”: “kohampa-Regular”,
“priceVariations”: [
{
“price”: “43”,
“sku”: “dfded”,
“variationId”: null,
“variationName”: “Regular”
}
],
“selecteQty”: 1,
“selectedPrice”: “43.00”,
“selectedVariation”: null,
“type”: “ITEM”
}
],
“t_value”: 91 }

this is my query

SELECT t_name.name FROM todo WHERE type="transaction"

i need to get “t_name.name” and sum(selecteQty). i am getting “empty object”.

I used UNNEST. now working fine
SELECT x.name,SUM(x.selecteQty) FROM todo AS c
UNNEST c.t_items AS x WHERE c.type=“transaction” GROUP BY (x.name)

1 Like

Hi @NaramukAbus,

I’m glad you found the answer. In the future, post your N1QL questions to the N1QL forums: https://forums.couchbase.com/c/n1ql - that forum is generally very quick to respond.

1 Like