Difference between revisions of "Aggregates with DISTINCT"
From SQLZOO
| Line 5: | Line 5: | ||
<p>You can find the number of <i>different</i> values using COUNT with DISTINCT</p> | <p>You can find the number of <i>different</i> values using COUNT with DISTINCT</p> | ||
<p>In 1915 four prizes were awarded in three different subjects:</p> | <p>In 1915 four prizes were awarded in three different subjects:</p> | ||
| − | <table><td><pre>SELECT yr, subject, winner | + | <table class='NoBorder'><td><pre>SELECT yr, subject, winner |
FROM nobel | FROM nobel | ||
WHERE yr=1915</pre> | WHERE yr=1915</pre> | ||
</td><td> | </td><td> | ||
| − | <table border="1" class=" | + | <table border="1" class="Bordered" style=""><tr> |
<th>yr</th> | <th>yr</th> | ||
<th>subject</th> | <th>subject</th> | ||
Latest revision as of 08:23, 18 July 2012
Nobel database
COUNT DISTINCT
You can find the number of different values using COUNT with DISTINCT
In 1915 four prizes were awarded in three different subjects:
SELECT yr, subject, winner FROM nobel WHERE yr=1915 |
|
COUNT(subject) gives 4; COUNT(DISTINCT subject) gives 3.
SELECT COUNT(subject), COUNT(DISTINCT subject) FROM nobel WHERE yr = 1915
SELECT COUNT(subject), COUNT(DISTINCT subject) FROM nobel WHERE yr = 1915