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