SQL Query Report problem

Hey guys,

I’m trying to learn how to make query reports. This is one I’ve written:

SELECT
    dn.name as "ID::100",
    dni.item_code as "Item Code::100",
    SUM(dni.qty) as "Quantity::100"
FROM
    `tabDelivery Note Item` dni, `tabDelivery Note` dn
GROUP BY
    dni.item_code
WHERE
    dn.docstatus = 1

This report works when I remove the WHERE clause at the end, but I get a syntax error otherwise:

ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE\n\tdn.docstatus = 1' at line 9")

Does anyone see what I’m doing wrong?

Solved, the WHERE clause needs to be before the GROUP BY clause.