The following examples show the use of column functions.
Example 1: This example shows how to find the average salary of all employees in the EMP table.
SELECT AVG(SALARY) FROM EMP
Example 2: This example shows how to find the maximum and minimum salaries in the EMP table for employees whose age is over 30.
SELECT MAX(SALARY), MIN(SALARY) FROM EMP WHERE AGE > 30;
Example 3: This example finds the sum of salaries for all employees whose age is 30 or less.
SELECT SUM(SALARY) FROM EMP WHERE AGE <= 30;
Example 4: This example counts the number of shipments which included a part with the number P3. Duplicates are not eliminated.
SELECT COUNT(*) FROM SHIPPART WHERE PNUM = 'P3'
Example 5: This example counts the exact number of part numbers contained in PARTLIST. Any duplicates are eliminated.
SELECT COUNT(DISTINCT PNUM) FROM PARTLIST
|
Copyright © 2014 CA.
All rights reserved.
|
|