Tring the following query but i get; Error Code: 1055. Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'PDC.PLG.LogDateTime' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
I know that this is because of only full group by mode; how can I refactor this sort of query?
SELECT
SUM(PLG.Qty) AS TotQty,
SUM(PLG.ScrapQty) AS ScrpQty,
(
SELECT SUM(PLL.Qty)
FROM ProductionLog AS PLL
INNER JOIN ProductionPlan PPP ON PPP.PlanId = PLL.PlanId
WHERE
DATE(LogDateTime) = DATE(PLG.LogDateTime) AND
LogType = 8 AND
PPP.StationId = PP.StationId
) AS RwrkQty,
DATE(PLG.LogDateTime) AS LogDate,
S.StationName
FROM ProductionLog AS PLG
INNER JOIN ProductionPlan AS PP ON PLG.PlanId = PP.PlanId
INNER JOIN Station AS S ON S.StationId = PP.StationId
WHERE PLG.Logtype IN (4)
GROUP BY S.StationId,DATE(PLG.LogDateTime)
tsql
tag: "... Do not use this tag for MySQL, ...". I'm replacing it withsql
which I guess is what you actually wanted. – sticky bit