When I use my query to select all data from the table I have a problem with the custnumber field. If custnumber is returned within the same month then it should group the results but only then.
This is my query:
SELECT MONTH(periode) AS maand,
YEAR(periode) AS jaar,
maandfacturen.verzenddatum,
maandfacturen.factuurnr,
maandfacturen.custnumber,
klantgegevens.bedrijfsnaam AS bedrijfsnaam,
maandfacturen.totaalbedragexcl,
maandfacturen.totaalbedragincl,
maandfacturen.betaald
FROM maandfacturen
LEFT JOIN klantgegevens ON maandfacturen.custnumber = klantgegevens.custnumber
WHERE
periode
LIKE '2023%'
GROUP BY custnumber
ORDER BY periode ASC, factuurnr ASC
This query does not work cause if I use GROUP BY custnumber it groups all records and thats not the result I need as all months also get grouped. After googling I found that I might need to use CASE to solve this but I am not sure how to use this.
Any help would be greatly appreciated.
Asked by James
(1 rep)
Jul 13, 2023, 11:28 AM
Last activity: Jul 13, 2023, 02:30 PM
Last activity: Jul 13, 2023, 02:30 PM