I have a query:
select e.Owner as 'Owner', COUNT(l.EnquiryID) as 'Total Sales Lines'
from DayBookQuoteLines l, DayBookEnquiries e
where l.EnquiryID = e.EnquiryID
and MONTH(e.enquirydate) = 8 and YEAR(e.enquirydate) = 2012
group by e.Owner
This returns the owner column which contains a name and a total column, but i wish to have two more columns where i apply an additional filter and count again, adding in:
l.LostStatusId =2
and
l.LostStatusId =3
So i’ll be left with a result set that looks like something like this:
Owner Total Lines Total Sold Total Lost
Person1 124 112 12
I cant seem to get the query right. I’m attempting to use sub-selects but am obviously missing something, any assistance would be appreciated.
You might conditionally count records by adding one when condition is satisfied.