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",
                       "The Lady and the Tramp",
                       "The Little Mermaid");
 85  (in minutes)
Comments Comments are left by visitors to FluffyCat.com and may or may not be accurate.
Comment by TheMadProfessor on 2013-07-06 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.

Sign in to comment on SQL Avg.