Example: Use ARRAY_AGG to Aggregate Salaries as Input to ARRAY_TO_JSON - 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™
Use ARRAY_AGG to aggregate the salaries of the job positions as input to ARRAY_TO_JSON, to obtain JSON objects as output.
The example uses the table(s) created earlier.
SELECT salary, (ARRAY_TO_JSON(ARRAY_AGG(pos ORDER BY empId, NEW varchararr5())) 
    RETURNS JSON(100) CHARACTER SET LATIN)
FROM employeeTable 
GROUP BY salary
ORDER BY salary;
Result:
salary 	 ARRAY_TO_JSON(ARRAY_AGG(…))
-----------------------------------
50000 	 ["engineer","engineer","salesman","salesman","manager"]
75000 	 ["engineer","salesman","manager"]
100000 	["engineer","salesman","manager"]
125000 	["manager","executive"]
150000 	["executive","executive"]
200000 	["executive"]
1000000   ["executive"]