About aggregate functions in SQL
• AVG: Average of the column. If you want to get the average of marks for a student then you can use this function as
select avg(marks) as average marks
• COUNT: Number of records. If you want to count number students who has got >50 marks in maths
where marks>50 and subject='maths'
• MAX: Maximum of the column. If you want to find out who has got maximun marks in any subject then
• MIN: Minimum of the column. This is opposite to the max function
• SUM: Sum of the column. To find out total marks of a student
select sum(marks) as total
Other than aggregate functions we can write our own user defined functions which will do desired operation; so that we need not write the same logic again and again. For example, having a function to take a comma separated value as input and retuning a table as output with splitted values in each row.
SQL functions are precompiled and cached so they are pretty fast in run time.
No responses found. Be the first to comment...