Beruflich Dokumente
Kultur Dokumente
Tell Me / Show Me
Tell Me / Show Me
COMMENTS
COUNT
Play late
SELECT comments (null)
Why are null values returned FROM d_play_list_items; Play early
in the query shown? There Play after cake cutting
are six comments listed, but Play first
the count function returned Play for the father
only five. Why?
Tell Me / Show Me
COUNT
Tell Me / Show Me
DISTINCT
SELECT year as ‘CD Year’
FROM d_cds;
The keyword DISTINCT is used to
CD Year
return only nonduplicate values or
combinations of nonduplicate 1997
2002
1999
Examine the query on the right.
Without using the keyword 2000
Tell Me / Show Me
1997
Using the DISTINCT keyword
1998
returned all the CD years exactly
once, with no duplicate values. 1999
2000
2001
2002
2004
Tell Me / Show Me
The keyword DISTINCT, when YEAR TITLE
1997 The Celebrants Live in Concert
used in a query selecting more 1998 Graduation Songbook
than one column, will return 1999 Songs from My Childhood
nonduplicate combinations of the 2000 Cape Diem
2000 Party Music for All Occasions
columns. Examine the two results
2001 Here Comes the Bride
sets shown here. Can you tell 2002 Back to the Shire
which query used the DISTINCT 2004 Whirled Peas
keyword? SELECT DISTINCT year, title
FROM d_cds;
YEAR TITLE
1997 The Celebrants Live in Concert
In this case, it's hard to tell, isn't it? 2000 Party Music for All Occasions
The results set on the top was 2002 Back to the Shire
returned using the DISTINCT 1999 Songs from My Childhood
2000 Carpe Diem
keyword. In both examples, there 2001 Here Comes the Bride
are no duplicate combinations of 1998 Graduation Songbook
year and title even though there 2004 Whirled Peas
are duplicate years.
Copyright © 2007, Oracle. All rights reserved. 9
COUNT, DISTINCT, NVL
SALARY
The keyword DISTINCT 24000 SUM(SALARY)
can be used with all group 17000 58000
functions. Using DISTINCT 17000
makes the function
consider only nonduplicate
SELECT SUM(DISTINCT salary)
values.
FROM employees
WHERE department_id = 90;
Tell Me / Show Me
When using DISTINCT with a
group function such as COUNT, SELECT COUNT (DISTINCT job_id)
the result set will return the FROM employees;
number of nonduplicate column
COUNT (DISTINCT job_id)
values.
12
Tell Me / Show Me
NVL
Tell Me / Show Me
Terminology
Key terms used in this lesson include:
COUNT (expression)
COUNT (DISTINCT expression)
DISTINCT
Summary
In this lesson you have learned to:
Summary
Practice Guide