-
sql count by company
i want to return a count of the number of lproductid's for each company, so far i have this query
select count(lproductid), companyname, customeragreementsent, customeragreementback
from tblcompanies
inner join tblCustomerAgreements as ca on tblcompanies.companyid = ca.companyid
inner join tblallsubscribercodes as tas on ca.companyid = tas.companyid
inner join ilabelserver.dbo.subscriber as isub on tas.subscribercode
= isub.smanucode
inner join ilabelserver.dbo.product as iprod on isub.lsubscriberid =
iprod.lsubscriberid
where customeragreementsent is not null and customeragreementback is null
group by lproductid, companyname,customeragreementsent, customeragreementback
but this does not pull back the correct results.
can anyone help?
-
Trim your GROUP BY clause:
from
Code:
group by lproductid, companyname,customeragreementsent, customeragreementback
to
Code:
group by companyname