HestonJames
Programmer
Hello Guys,
This will be a simple enough question I'm sure, I suspect its caused by datatype mismatches of some kind between int's and float's or something, maybe you can help?
I have a simple query which looks like this:
This query runs without error however, the AVG() returned seems to be rounded down, rather than a proper decimal placed average of the column values that I really want.
So for instance, example result sets might look like this:
Highest: 2
Lowest: 1
Average: 1
or
Highest: 4
Lowest: 1
Average: 1
Now, am I using Avg() correctly here? or should I be using another method?
At the moment I'm able to solve the issue by doing something like this: Where I cast the value as a float instead of what I'm guessing is an Int.
I'm just interested to see if this is the correct way of handling it, or is there is a better built in method to be using?
Cheers all,
Heston
This will be a simple enough question I'm sure, I suspect its caused by datatype mismatches of some kind between int's and float's or something, maybe you can help?
I have a simple query which looks like this:
Code:
Select Max(message_count.messagecount) As Highest,
Min(message_count.messagecount) As Lowest,
Avg(message_count.messagecount) As Average
From (
Select MessageLog.Device_ID,
Count(Distinct MessageLog.Media_ID) AS MessageCount
From MessageLog
Group By MessageLog.Device_ID
) As message_count
This query runs without error however, the AVG() returned seems to be rounded down, rather than a proper decimal placed average of the column values that I really want.
So for instance, example result sets might look like this:
Highest: 2
Lowest: 1
Average: 1
or
Highest: 4
Lowest: 1
Average: 1
Now, am I using Avg() correctly here? or should I be using another method?
At the moment I'm able to solve the issue by doing something like this: Where I cast the value as a float instead of what I'm guessing is an Int.
Code:
Select Max(message_count.messagecount) As Highest,
Min(message_count.messagecount) As Lowest,
Avg([COLOR=#ff0000]cast(message_count.messagecount as float)[/color]) As Average
From (
Select MessageLog.Device_ID,
Count(Distinct MessageLog.Media_ID) AS MessageCount
From MessageLog
Group By MessageLog.Device_ID
) As message_count
I'm just interested to see if this is the correct way of handling it, or is there is a better built in method to be using?
Cheers all,
Heston