Wednesday, January 26, 2011

GROUP FUNCTION

      Group functions operate on group of rows and return one value for the ENTIRE GROUP. As a group is consdered the entire table or just some portions of the table grouped by some common atribute.

      Group functions are:

      COUNT, MAX, MIN, AVG, SUM, DISTINCT

      COUNT - It returns the number of rows in the query. For example: we want to know number of employees wich have salary = 10000

      clip_image001[8]

      What will happen if in the group are rows with NULL values? They will not be considered!!!

      For example: We have in the entire table 107 rows, but only 35 from them are with non-null values in collumn commission_pct

      clip_image002[7]

      clip_image003[8]

      DISTINCT - we can use it to retrieve only unique data entries.

      Example:

      clip_image004[4]

      There will be selected just 57 rows. (all duplicate values will be ignored)

      AVG - it returns the average value of the column or expression. For example:

      clip_image005[4]

      clip_image006[4]

      As we can see from the examples, the general syntax from the AVG functions is:

      AVG([DISTINCT] EXPRESSION)

      MAX Function - it will return the highest number (when operation on numeric values), latest date (when operating on date) and the world that appears at last alphabetically ( when operating on char data.

      Examples:

      clip_image007[4]

      clip_image008[4]

      MIN Function - it is exactly the opposite of the MAX function. For example:

      clip_image009

      clip_image010

      SUM Function -it returns the sum of values of expression. For more information, pls check ORACLE DOCUMENTATION Examples:

      clip_image011

More functions are available under http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions163.htm

No comments:

Post a Comment