. SQL . SQL Avg
SQL Avg
SQL Avg() Example
Q: If I were to have an Disney DVD mini-marathon with the films Pinocchio, The Little Mermaid, Lady and the Tramp, Hercules, and Mulan how much average entertainment will I be getting, chronographically?
Select Avg(Film_Length)
From Film_Table
Where Film_Title in ("Pinocchio",
"Hercules",
"Mulan",
"The Lady and the Tramp",
"The Little Mermaid");
85 (in minutes)
| Sign In |
| to add your own comment |
| Comment by TheMadProfessor Rate this Comment |
A Gotcha to keep in mind for column functions in general is that for aggregate function computations other than COUNT(*), rows containing NULL are excluded. A common misconception I've seen is expecting NULL to be equated to a value of zero, when instead it is simply ignored. For example, if a sixth movie was added to the IN values above that had a NULL for film length, you would get the same result as above computed by (80+90+90+80+85)/5, instead of (80+90+90+80+85+0)/6. The rows containing NULL values are completely ignored in the computation. |