I’m experiencing an issue with my MySQL query that worked correctly until I added a new line of computation. Specifically, the issue began with the introduction of this line in my SELECT statement:
COUNT(0) * COUNT(MAX(hdmhdrprice.dmduprice)) AS 'Total Quantity'
The affected portion of my query looks like this:
COUNT(MAX(hdmhdrprice.dmduprice)) AS 'Unit Value',
COUNT(0) AS 'On Hand per Count',
COUNT(0) * COUNT(MAX(hdmhdrprice.dmduprice)) AS 'Total Quantity'
Now, I am facing an ErrorNr. 1111 with my entire query:
SELECT CONCAT(hgen.gendesc, ',',
(CASE WHEN hdmhdr.brandname IS NULL THEN '' ELSE CONCAT(' ', hdmhdr.brandname) END),
(CASE WHEN hdmhdr.dmdnost IS NULL THEN '' ELSE CONCAT(' ', CONVERT(hdmhdr.dmdnost, CHAR(14))) END),
(CASE WHEN hstre.stredesc IS NULL THEN '' ELSE hstre.stredesc END),
(CASE WHEN hform.formdesc IS NULL THEN '' ELSE CONCAT(' ', hform.formdesc) END),
(CASE WHEN hroute.rtedesc IS NULL THEN '' ELSE CONCAT(' ', hroute.rtedesc) END)) AS 'itemdesc',
(CASE WHEN hform.formdesc IS NULL THEN '' ELSE CONCAT(' ', hform.formdesc) END) AS 'Unit of Measurement',
hdmhdr.dmdcomb AS 'Stock No:',
COUNT(MAX(hdmhdrprice.dmduprice)) AS 'Unit Value',
COUNT(0) AS 'On Hand per Count',
COUNT(0) * COUNT(MAX(hdmhdrprice.dmduprice)) AS 'Total Quantity'
FROM hdmhdr
LEFT JOIN hroute ON hdmhdr.rtecode = hroute.rtecode
LEFT JOIN hstre ON hdmhdr.strecode = hstre.strecode
INNER JOIN hdruggrp ON hdruggrp.grpcode = hdmhdr.grpcode
INNER JOIN hform ON hform.formcode = hdmhdr.formcode
INNER JOIN hgen ON hgen.gencode = hdruggrp.gencode
INNER JOIN hdmhdrprice ON hdmhdrprice.dmdcomb = hdmhdr.dmdcomb
WHERE hdmhdr.dmdcomb IS NOT NULL
GROUP BY itemdesc
What could be causing this function error? The query was running smoothly prior to adding these aggregate computations.