Goodmorning everyone.
I'm going crazy
I need to extract the number of invoices from the current year per customer.
in my table tbl_preventivi I have the field anagrafica_id for the customer and date_prev for the date of the invoice.
this is my code.
$anno = date('Y');
SELECT tbl_preventivi.anagrafica_id, Count(tbl_preventivi.preventivo_id) AS totale
FROM tbl_preventivi
GROUP BY tbl_preventivi.anagrafica_id, Year(tbl_preventivi.data_prev)
HAVING ((Year(tbl_preventivi.data_prev) = ".$anno.") AND (tbl_preventivi.anagrafica_id=".$_GET['anagrafica_id']."))
i am sure that in the test i am doing the result must be 1, instead the query is null.
if I remove
(Year(tbl_preventivi.data_prev) = ".$anno.") AND
the query works and returns 6 (which is the number of invoices made even in previous years).
where am i wrong?