May 8, 2008 at 3:34 pm
Is there a way in a view or select statements to summarize data into a single table? My final output needs to be CloseReason, CRCount, TotalCRCount, Percent
Where the TotalCount is the sum of CRCount and the Percent is quite simple (CRCount/TotalCRCount)....
This is my starting query, however I don't know how to get the CloseReason, CRCount, TotalCRCount, Percent all in one output:
select CloseReason, Count(*) as CRCount
from tblOpportunities t
inner join tblOpportunityStatuses k
on t.OpportunityStatus = k.OpportunityStatus
Where k.OpportunityStatusKeyID = 2 and t.CloseReason is Not Null
group by CloseReason
I know how to do this in a stored procedure, but not in a view or select statements... Any help is much appreciated.
May 8, 2008 at 3:51 pm
select CloseReason
, Count(*) as CRCount
, TotalCount as sum(CRcount)
, percent as (SUM(CRCount)/sum(TotalCRCount))
from tblOpportunities t
inner join tblOpportunityStatuses k
on t.OpportunityStatus = k.OpportunityStatus
Where k.OpportunityStatusKeyID = 2 and t.CloseReason is Not Null
group by CloseReason
?
May 9, 2008 at 7:02 am
Thank-You...
I did try this and it doesn't recognize CRcount...
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply