HestonJames
Programmer
Hello Guys,
I've got the following example dataset for you to play with, basicly its a set of very basic weather data, you'll see at the moment that it calculates the average temperature for the records which are pulled out.
What I'm also looking to do it pull the most common 'description' string, which for the given test dataset would be 'cloudy', this allows me to give a good average description for the weather.
What would you suggest to be the best way at going about that?
Cheers all,
Heston
I've got the following example dataset for you to play with, basicly its a set of very basic weather data, you'll see at the moment that it calculates the average temperature for the records which are pulled out.
Code:
Declare @WeatherReport Table (
Location_ID int,
Description varchar(50) Collate Database_Default,
Temp_C int
)
Insert Into @WeatherReport
Values (1, 'Sunny', 10)
Insert Into @WeatherReport
Values (1, 'Sunny', 15)
Insert Into @WeatherReport
Values (1, 'Sunny', 20)
Insert Into @WeatherReport
Values (1, 'Cloudy', 30)
Insert Into @WeatherReport
Values (1, 'Cloudy', 10)
Insert Into @WeatherReport
Values (1, 'Cloudy', 12)
Insert Into @WeatherReport
Values (1, 'Cloudy', 13)
Insert Into @WeatherReport
Values (1, 'Cloudy', 19)
Insert Into @WeatherReport
Values (1, 'Cloudy', 30)
Select Avg(Temp_C) As AverageTemperature
From @WeatherReport
What I'm also looking to do it pull the most common 'description' string, which for the given test dataset would be 'cloudy', this allows me to give a good average description for the weather.
What would you suggest to be the best way at going about that?
Cheers all,
Heston