COUNT counts the number of non-NULL items. Any NULL items are ignored.
COUNT(*) - Count rows in the table
COUNT(Major) - Count the number of (duplicate and unique) Majors in the table
In the DQ exercise example,
COUNT(Major) may have the same result as
COUNT(*), but what it represent differs.
Major column has duplicate values.
COUNT(DISTINCT Major) !=
Major column has null values.
COUNT with other constraints
COUNT is an aggregate function. You may replace
COUNT with other aggregate function to explain yourself what does other aggregate function does with other constraint.
Rows are removed when the constraint in the SQL query clause is not met.
COUNT(...) may differ in number when you have constraints in the following SQL query clauses (and also by SQL query clause order from top to bottom):
COUNT(...) counts the remaining number of rows.
ShareWomen < 0.3
In example 1, rows with
ShareWomen >= 0.3 are removed.
COUNT(Major) returns the number of non-NULL Majors where ShareWomen < 0.3.
In example 2,
COUNT(Major) counts the number of majors in each
Major_category = "Arts"
OR Major_category = "Engineering
In example 3,
COUNT(Major) counts the number of majors in
To count number of rows use
To count number of
To count number of items in the
COUNT(...) represents is determined by what rows are removed by these constraints in the SQL query.