Aggregate functions in Oracle usage of Count, max, Min, Sum, AVG, and NVL functions

Source: Internet
Author: User

aggregate functions in Oracle usage of Count, max, Min, Sum, AVG, and NVL functions

The Grouping function aggregate function performs a calculation on a column in a set of rows and returns a single value. The aggregate function ignores null values. Aggregate functions are often used in conjunction with the GROUP BY clause of a SELECT statement, so they are sometimes referred to as grouping functions. This type of function is typically applied to report statistics, and the following shows the application of Oracle's common aggregation functions.

The introduction of a grouping function acts on a set of data and returns a value to a set of data.

The common grouping functions are:

Count


Used to calculate the number of valid data

Min

Returns the minimum value of a numeric column or computed column

Select Gi.id,

Gi.game_instance_name,

Gi.draw_no,

Gi.draw_date,

Count(*) ticketnumber,--- used to calculate the number of valid data

       NVL ( min (tt.total_bets), 0 ) totalentry, -- null use 0

       NVL ( min (Tt.total_amount), 0 ) totalturnover ---- null use 0

from te_bg_ticket tt, Bg_game_instance gi, GAME g

where tt.bg_game_instance_id = gi.id

and gi.game_id = g.game_id

and gi.status =1

and tt.ticket_type =1

and tt.is_count_in_pool =1

and g.game_id =' 4028822f483fd59401483fe62dc4000d '

and g.game_type_id =6

Group by gi.id, Gi.game_instance_name, Gi.draw_no, Gi.draw_date

having Count (*) > 0

order by gi.draw_no

Max

Returns the maximum value of a numeric column or computed column

As with the minimum value usage

Sum

Returns the sum of a numeric column or computed column

Select Gi.id,

Gi.game_instance_name,

Gi.draw_no,

Gi.draw_date,

Count(*) ticketnumber,--- used to calculate the number of valid data

       NVL ( sum (tt.total_bets), 0 ) totalentry, -- null use 0

       NVL ( sum (Tt.total_amount), 0 ) totalturnover ---- null use 0

from te_bg_ticket tt, Bg_game_instance gi, GAME g

where tt.bg_game_instance_id = gi.id

and gi.game_id = g.game_id

and gi.status =1

and tt.ticket_type =1

and tt.is_count_in_pool =1

and g.game_id =' 4028822f483fd59401483fe62dc4000d '

and g.game_type_id =6

Group by gi.id, Gi.game_instance_name, Gi.draw_no, Gi.draw_date

having Count (*) > 0

order by gi.draw_no

Avg

Returns the average of a numeric column or computed column

Usage is the same as max,min,sum.

NVL function

NVL (EXPR1,EXPR2) If the first parameter of Oracle is empty then the value of the second parameter is displayed, and if the value of the first parameter is not NULL, the first parameter is displayed.


Aggregate functions in Oracle usage of Count, max, Min, Sum, AVG, and NVL functions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.