Monday, 26 December 2011

Avg Function. Group By, Having Keywords.

To find the average DensityPerKmSq for each continent,Query is below.


Note :  Please note that for continent Europe,eventhough there are 4 countries, the average is taken for only 3 countries. This is because the country France has Null Value for DensityPerKmSq (which means that it is an unknown value). Hence it is not taken into account.

Further more ,Please note that eventhough for continent Europe the Average value for DensityPerKmSq is 228.67,by default the value is rounded off to the lower value of 228(and not to 229)

Further more, Please note that apart from the aggregate function (Aggregate function is avg(a.DensityPerKmSq)), the column in select query is a.continent. So it should be in group by clause.

The having clause is equivalent to where clause but the having clause is always used along with group by clause.

1 comment:

  1. Dude, nice info for the sql starters..but try using better colour combinations. Good luck..

    ReplyDelete