I am trying to figure out what the query syntax is for an inline sum for a specific field in an object array. My data is structured like this
CREATE TABLE "orders" (
order_id int8,
tax_lines jsonb
);
INSERT INTO "orders"(order_id, tax_lines) VALUES (4521745668, '[
{
"rate": 0.029,
"price": "0.43",
"title": "CO State Tax"
},
{
"rate": 0.00985,
"price": "0.15",
"title": "Boulder County Tax"
},
{
"rate": 0.0496,
"price": "0.74",
"title": "Boulder Municipal Tax"
}
]');
The result i am trying to achieve is
order_id cumulative_tax_rate
4521745668 .08845
This is as far as i have gotten
SELECT
o.order_id,
SUM((jsonb_array_elements(o.tax_lines) ->> 'rate')::numeric) AS cumulative_tax_rate
FROM orders o WHERE o.order_id = '4521745668'
but it keeps asking for a GROUP BY clause which I would like to avoid. I was wondering if it is possible to perform this aggregation at the row level without a group by clause and, if so, what that syntax might look like?
Thank you in advance.
INSERT INTO >>>> "MY_TABLE" <<<<?shopify_order_idandjsondataaren't in yourorderstable