johnisotank
Technical User
Hi all,
could someone tell where i've gone wrong with this pls..
My statement looks at 2 tables. tblLift and tblJobMethods.
the tables link on field JobNo.
I want to pull in the Product field and then count how many times that product appeared for jobs beginning DA and then jobs beginning RE.
There is just one record in tblLift (JobNo = RE1, Product = ACETONE).
There are 4 records in tblJobMethods
So the query result should be:
Product, DA, RE
ACETONE, 0, 1
but it is actually saying
Product, DA, RE
ACETONE, 0, 4
I think DISTINCT needs adding to this but wherever I put it it keeps returning errors.
Thanks
John
could someone tell where i've gone wrong with this pls..
My statement looks at 2 tables. tblLift and tblJobMethods.
the tables link on field JobNo.
I want to pull in the Product field and then count how many times that product appeared for jobs beginning DA and then jobs beginning RE.
Code:
SELECT Product,
Count(CASE WHEN LEFT(a.JobNo,2) = 'DA' THEN a.Product END) AS 'DA Count',
Count(CASE WHEN LEFT(a.JobNo,2) = 'RE' THEN a.Product END) AS 'DA Count'
FROM tblLift a LEFT JOIN
tblJobMethods b ON a.JobNo = b.JobNo
GROUP BY a.Product
There is just one record in tblLift (JobNo = RE1, Product = ACETONE).
There are 4 records in tblJobMethods
So the query result should be:
Product, DA, RE
ACETONE, 0, 1
but it is actually saying
Product, DA, RE
ACETONE, 0, 4
I think DISTINCT needs adding to this but wherever I put it it keeps returning errors.
Thanks
John