Example: Using JSON_AGG with GROUP BY and with All Parameter Names - Advanced SQL Engine - Teradata Database

JSON Data Type

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
September 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
gzn1554761068186.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1150
lifecycle
previous
Product Category
Teradata Vantageā„¢
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}]