Teradata provides many functions which can be used to fulfil various user requirements, click on the required function to get detail
SELECT COALESCE(NULL,NULL,'Teradata');
Output: Teradata
SELECT COALESCE(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1);
Output: 1
SELECT TYPE('Teradata');
Output: VARCHAR(8) CHARACTER SET UNICODE
SELECT TYPE(454.44);
Output: DECIMAL(5,2)
SELECT TYPE(current_time);
Output: TIME(0) WITH TIME ZONE
SELECT TYPE(current_date);
Output: DATE
Syntax:
XMLAGG(column_to_merge [, ORDER BY sort_column_name [DESC|ASC])
CREATE MULTISET VOLATILE TABLE xmlaggr_example
(
id INTEGER,
code CHAR(1)
)
PRIMARY INDEX(id)
ON COMMIT PRESERVE ROWS;
INSERT INTO xmlaggr_example(1,'A');
INSERT INTO xmlaggr_example(1,'B');
INSERT INTO xmlaggr_example(1,'C');
INSERT INTO xmlaggr_example(1,'D');
SELECT id,
TRIM(TRAILING ',' FROM (XMLAGG(code||',' ORDER BY code DESC) (VARCHAR(100)))) merged_column
FROM xmlaggr_example
GROUP BY 1
id merged_column
-- --------------
1 D, C, B, A
Points to Note
SELECT MAX(salary) FROM tutorial_db.employee;
Output: 5000.00
SELECT dept_no, MAX(salary) FROM tutorial_db.employee GROUP BY dept_no; --Maximun salary in each depatment
Output:
dept_no Maximum(salary)
----------- --------------------
100 5000.00
200 3000.00
300 2850.00
SELECT MIN(salary) FROM tutorial_db.employee;
Output: 800.00
SELECT dept_no, MIN(salary) FROM tutorial_db.employee GROUP BY dept_no; --Minimum salary in each depatment
Output:
dept_no Minimum(salary)
----------- --------------------
100 1300.00
200 800.00
300 950.00
SELECT SUM(salary) FROM tutorial_db.employee;
Output: 29025.00
SELECT dept_no, SUM(salary) FROM tutorial_db.employee GROUP BY dept_no; --Sum of salary in each depatment
Output:
dept_no Sum(salary)
----------- --------------------
100 8750.00
200 10875.00
300 9400.00
SELECT AVG(salary) FROM tutorial_db.employee;
Output: 2073.21
SELECT dept_no, AVG(salary) FROM tutorial_db.employee GROUP BY dept_no; --Average salary in each depatment
Output:
dept_no Average(salary)
----------- --------------------
100 2916.67
200 2175.00
300 1566.67
SELECT COUNT(*) FROM tutorial_db.employee;
Output: 14
SELECT COUNT(commission) FROM tutorial_db.employee; --If column is mentioned in count then null will be ignored in counting
Output: 4
SELECT dept_no, COUNT(salary) FROM tutorial_db.employee GROUP BY dept_no; --Count of employees by department
Output:
dept_no Count(*)
----------- -----------
100 3
200 5
300 6