SQL offers five built in aggregate
functions:
(i) Average: avg
returns the average value of a given column.
Example:
Find the average account balance.
Solution:
Select avg(balance) from account.
(ii) Minimum: min
returns the smallest value in a given column.
Example:
Find the minimum account balance at the perryridge branch.
Solution:
select min(balance) from account where branch-name = “perryridge”.
(iii) Maximum: max
returns the largest value in a given column.
Example:
Find the largest account balance in the bank.
Solution:
select max(balance) from account.
(iv) Total: sum
returns the sum of the numeric values in a given
column.
Example:
Find the total account balance of Mirpur branch.
Solution:
select sum(balance) from account where branch-name = “Mirpur”.
(v) Count: count
returns the total number of values in a given
column.
Example:
Find the number of tuples in the customer relation.
Solution:
select count(*) from customer.
No comments:
Post a Comment