I have this query and, for some reason, I am getting an error message when I write different functions related to dates (TO_DATE, DATEADD, DATESUB, and others):
SELECT
t.dates AS dates
, COUNT(DISTINCT t.client_id) AS client_id
FROM
(
SELECT
invoices
.client_id
AS client_id
, invoices
.date
AS dates
FROM invoices
) AS t
WHERE
TO_DATE(t.dates) BETWEEN t.dates AND DATEADD(month, '3', t.dates)
GROUP BY 1
ORDER BY 1
Sadly I could not find any solution. What could it be?
Thanks in advance!