View Single Post
  #12 (permalink)  
Old 12-10-09, 13:03
ozzii ozzii is offline
Registered User
 
Join Date: Mar 2007
Posts: 194
Ok, a number of you have made suggestions buts what the correct SQL to obtain the correct results?

Basically I want the average number of enquiries for each DAY OF THE WEEK i.e Mon-Sun.

I've run both SQL queries in both MySQL and SQL Server and they both produce the same results.

As far as I gather the second SQL query doesn't produce the desired results because the sub-query is grouping on the day of the week and since there are only ever 7 days in a week it will group the 2 Mondays together with 10 as the total. In other word it only produces 7 rows of data for each day of the week. The main select statement then does an avg on this sub query and since the sub-query now only has 1 row to represent Monday then the avg will always equal the total in the subquery for each day of the week becuase you are always dividing by 1.

Now using the first SQL query, by default the AVG function seems to produce the avg as a whole number - this is in SQL Server. I've tried the following to display the average with 2 decimal places but it doesnt work. Is there any way to achieve this?

Code:
ROUND(AVG(total_enquiries),2) as avg_enquiries
Reply With Quote