Beruflich Dokumente
Kultur Dokumente
Objectives
Purpose
COUNT
SELECT comments
Six rows of comments are listed in FROM d_play_list_items;
the table, including the empty (null)
COMMENTS
comment, but the count function Play late
returned only five. Why? (null)
Play early
Play after cake cutting
Play first
Because COUNT specifically
Play for the father
counts the comments column but
ignores the null value in the column. SELECT COUNT(comments)
FROM d_play_list_items;
COUNT (COMMENTS)
5
For example, to find out how many
of DJs on Demand CDs were
produced before 2001, COUNT can
be used in the SELECT statement.
6 Copyright © 2013, Oracle and/or its affiliates. All rights
reserved.
COUNT, DISTINCT, NVL
COUNT (*)
DISTINCT
2000
Examine the query on the right. 2002
Without using the keyword 1999
DISTINCT, the query returned all of 2000
the year values from the DJs on 2001
Demand D_CDS table, including 1998
the duplicate values. 2004
DISTINCT Example
1997
Using the DISTINCT keyword
1998
returned all of the CD years
1999
exactly once, with no duplicate
2000
values.
2001
2002
2004
DISTINCT Non-duplicate
Using DISTINCT
SELECT SUM(salary)
FROM employees
WHERE department_id = 90;
The keyword DISTINCT can
SALARY
be used with all group
24000 SUM(SALARY)
functions. Using DISTINCT 58000
17000
makes the function consider
17000
only non-duplicate values.
SELECT SUM(DISTINCT salary)
FROM employees
Why do the two statements WHERE department_id = 90;
on the right produce different
SALARY
results? 24000 SUM(DISTINCT
SALARY)
17000 41000
17000
column values.
SELECT COUNT (DISTINCT salary)
FROM employees;
NVL
NVL (cont.)
Terminology
Summary