How to use grouping correctly in this query:
$sQuery = "SELECT id,DATE(A.Inspection_datetime) AS Date,
A.Model, COUNT(A.Serial_number) AS Qty,
B.name
FROM inspection_report AS A
LEFT JOIN Employee AS B
ON A.NIK=B.NIK
GROUP BY Date, B.name".$sWhere.$sOrder.$sLimit;
i’m really new in concatenation.
You need to GROUP BY both ‘id’ and ‘A.Model’ too, at least in most SQL DBMS (MySQL has laxer rules in this area). You need GROUP BY to come after the WHERE clause and before the ORDER BY clause. Hence:
Note that you must make sure there are spaces to separate the various clauses that you concatenate together; I added a space at each end of
$sGroupBy(and afterB.NIK) to make sure that part was OK.