Example: Using JSON_AGG with GROUP BY and with All Parameter Names - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905
The example shows how to use JSON_Agg to assign parameter names in the resulting JSON instance and use the GROUP BY clause.
SELECT JSON_agg(empID AS id, empName AS name, empAge AS age) 
FROM emp_table
GROUP BY company;
Result: The query returns one line of output (note, output line is wrapped).
JSON_agg(empID AS id,empName AS name,empAge AS age)
---------------------------------------------------
[{"id":3,"name":"Someone","age":24},
{"id":1,"name":"Cameron","age":24},
{"id":2,"name":"Justin","age":34}]