October 22, 2013 at 3:21 am
Hi,
I am having an issue with an averageg i am trying to calculate. Here is the query. The results i am getting back are 27.00, 12.00 etc, when they should be 27.38, 12.67 etc.
Any advice?
SELECT
Week,
Hospital,
CAST( avg(Length_Of_Stay) AS DECIMAL(10,2)) as Average_LoS
FROM table
GROUP BY
Week,
Hospital
October 22, 2013 at 3:25 am
October 22, 2013 at 4:40 am
james.ingamells (10/22/2013)
Hi,SELECT
Week,
Hospital,
CAST( avg(Length_Of_Stay) AS DECIMAL(10,2)) as Average_LoS
FROM table
GROUP BY
Week,
Hospital
This "Length_Of_Stay" might be INTEGER in your table.
So that AVG function returns INTEGER values.
You should convert data to decimal then get AVG value.
October 22, 2013 at 8:36 am
You can also do you own AVG like =1.0*Total_Days/Total_Count, that 1.0 it will you give you bunch of decimals places,
AVG has its own defaults I think.
Mario
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply