Wednesday, January 26, 2011

Calculating Averages (Part 1)

You can calculate average values with the AVG function as shown below. The second statement double checks the answer:

SQL> select avg(num_rows)
  2  from dba_tables
  3  where num_rows is not null
  4  /

AVG(NUM_ROWS)
-------------
   153051.912

SQL> select sum(num_rows) / count(*)
  2  from dba_tables
  3  where num_rows is not null
  4  /

SUM(NUM_ROWS)/COUNT(*)
----------------------
            153051.912

SQL>

Footnote: Since writing this post I have noticed that it is slightly misleading.
Go to part 2 for details.

No comments:

Post a Comment