0% found this document useful (0 votes)
16 views10 pages

Column/Aggregate Functions: by Neil A. Basabe

Column functions are used to summarize columns or expressions. Some common column functions include SUM to total values, AVG to calculate the average, MIN and MAX to find smallest and largest values, and COUNT to count rows. An example query uses several column functions like SUM, AVG, MIN, MAX, and COUNT to analyze data from an EMPLOYEE table, grouping results and applying conditions with clauses like GROUP BY and HAVING. Proper use of column functions, GROUP BY, and HAVING allows flexible analysis of column data in SQL queries.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
16 views10 pages

Column/Aggregate Functions: by Neil A. Basabe

Column functions are used to summarize columns or expressions. Some common column functions include SUM to total values, AVG to calculate the average, MIN and MAX to find smallest and largest values, and COUNT to count rows. An example query uses several column functions like SUM, AVG, MIN, MAX, and COUNT to analyze data from an EMPLOYEE table, grouping results and applying conditions with clauses like GROUP BY and HAVING. Proper use of column functions, GROUP BY, and HAVING allows flexible analysis of column data in SQL queries.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 10

COLUMN/AGGREGATE

FUNCTIONS
By
Neil A. Basabe
COLUMN FUNCTIONS
• Column functions are used to summarize
columns or expressions.

09/30/2020 Prepared by: SB Satorre 2


COLUMN FUNCTIONS - 1
1. SUM - returns the total value of the values in a given column|
expression.
SUM(column-name|expression)

2. AVG - retruns the average value of the values in a given


column|expression.
AVG(column-name|expression)

3. MIN - returns the smallest value of the values in a given


column|expression.
MIN(column-name|expression)

09/30/2020 Prepared by: SB Satorre 3


COLUMN FUNCTIONS - 2
4. MAX - returns the largest value of the values in a given
column|expression.
MAX(column-name|expression)

5. COUNT(*) - returns the number of the rows in a given


column.

6. COUNT DISTINCT - returns the number of unique non-


null rows of a column.
COUNT (DISTINCT column-name)
09/30/2020 Prepared by: SB Satorre 4
EXAMPLE
SELECT SUM(SALARY) AS "TOTAL-EMP-SALARY",

AVG(SALARY) AS "AVERAGE-EMP-SALARY",

MIN(SALARY) AS "SMALLEST-EMP-SALARY",

MAX(SALARY) AS "LARGEST-EMP-SALARY",

COUNT(*) AS "NO. OF EMPLOYEES",

COUNT (DISTINCT WORKDEPT) AS "NO. OF DEPARTMENTS"

FROM EMPLOYEE

09/30/2020 Prepared by: SB Satorre 5


THE COMPLETE SQL SELECT STATEMENT
SELECT . . .

FROM . . .

[WHERE . . .]

[GROUP BY . . .]

[HAVING . . .]

[ORDER BY . . .]

[FETCH FIRST . . . ONLY]

09/30/2020 Prepared by: SB Satorre 6


GROUP BY
The GROUP BY clause tells DBM which rows of
information are to be grouped together based
upon values in a column(s).
Columns with the same values are group
together as one row or record.

09/30/2020 Prepared by: SB Satorre 7


HAVING
The HAVING clause tells DBM which group(s) of
information are to be returned in the cursor
based upon some conditions.

The grouped rows that satisfy the condition are


returned in the cursor.

09/30/2020 Prepared by: SB Satorre 8


CAUTION!
GROUP BY and/or HAVING

Only applies to queries with COLUMN


FUNCTIONS in the SELECT clause

09/30/2020 Prepared by: SB Satorre 9


Laboratory Exercises

You might also like