I'm working on trying to figure out how to divide a Count(Criteria) / Count(*) and am running into an issue.
Background: I have Values (Red, Green) and I need to get the percentage 'green' everyday to display on a bar graph.
One day works great but when it gets to two days it errors out.
On the inner query i need to add
But it gives me the error "The inner query returned multiple values" and it can't divide right.'
What I need it to do is say 9/8/2010 Green = 50/ total count (100) = 50% then 9/9/2010 = 75/100 = 75%
I need it to return the dates and percentages but am having trouble figuring out... Any ideas?
Background: I have Values (Red, Green) and I need to get the percentage 'green' everyday to display on a bar graph.
One day works great but when it gets to two days it errors out.
Code:
Select
Convert(varchar,[DateTime],101) AS 'Date',
(
select count([status])
FROM [default_bsd_qa_db].[dbo].[SQA_DASH_SYNT_TRAN_LOG] NoLock
WHERE [DateTime] >= DATEADD(month,-1,GETDATE())
AND [STATUS]='Green'
)
/cast(count([Status]) as float)*100 as Uptime
FROM [default_bsd_qa_db].[dbo].[SQA_DASH_SYNT_TRAN_LOG] NoLock
WHERE [DateTime] >= DATEADD(month,-1,GETDATE())
Group By Convert(varchar,[DateTime],101)
On the inner query i need to add
Code:
Group By Convert(varchar,[DateTime],101)
But it gives me the error "The inner query returned multiple values" and it can't divide right.'
What I need it to do is say 9/8/2010 Green = 50/ total count (100) = 50% then 9/9/2010 = 75/100 = 75%
I need it to return the dates and percentages but am having trouble figuring out... Any ideas?