This has been bothering me all day:
I want to do 2 counts in 1 table. The first counts how many shops in total, the second should count the shops in total where the price is lower than tsuppliers.lowestprice
So basically I want to combine the second query into the first:
SELECT tshops.shopID, tshops.OfficialName, tsuppliershopinfo.ContactName, tsuppliershopinfo.ContactMail, Count(distinct tresults.pID) AS AantalVanpID
FROM (tsupplierproducts
INNER JOIN tresults ON tsupplierproducts.pID = tresults.pID)
INNER JOIN (tsuppliershopinfo INNER JOIN tshops ON tsuppliershopinfo.shopID = tshops.shopID) ON tresults.shopID = tsuppliershopinfo.shopID
WHERE (((tsupplierproducts.supplierID)=2)) AND tresults.starttime BETWEEN DATE_SUB(CURDATE(), INTERVAL 14 DAY) AND DATE_ADD(CURDATE(),INTERVAL 1 DAY)
GROUP BY tshops.shopID, tshops.OfficialName, tsuppliershopinfo.ContactName, tsuppliershopinfo.ContactMail;
The second (notice that there’s only one extra condition in the where-clause):
SELECT tresults.shopID, Count(distinct tresults.pID) AS AantalVanpID
FROM tsupplierproducts INNER JOIN tresults ON tsupplierproducts.pID = tresults.pID
WHERE (((tsupplierproducts.supplierID)=2) AND ((tresults.Price)<tsupplierproducts.LowestPrice)) AND tresults.starttime BETWEEN DATE_SUB(CURDATE(), INTERVAL 14 DAY) AND DATE_ADD(CURDATE(),INTERVAL 1 DAY)
GROUP BY tresults.shopID;
How can I combine the second query into the first query?
Thanks!
1 Answer