Creating a variable and filtering the output
Create a variable to calculate the total price for each item and use it to filter your
output.
Procedure
Results
The full query should look like
this:
FROM order AS o
UNNEST o.items
LET $total = toDecimal(qty * price)
WHERE $total > 1000
JOIN customer AS c ON c.custid = o.custid
WHERE c.rating > 650
SELECT {
c.name,
c.rating,
o.orderno,
itemno,
total_price = $total
} ORDER BY $total DESC LIMIT 1
It return the following
result:
[
{
"name": "T. Cruise",
"rating": 750,
"orderno": 1002,
"itemno": 460,
"total_price": 9594.05
}
]