How do I add a date condition to my request?
I have this SQL statement. It works and I need to add one more condition. I need to sort it by date. is my date string.
SELECT dd.caption, COUNT(t.occurence)
FROM transaction t
INNER JOIN dict_departments dd
ON dd.id = t.terminal_id
GROUP BY dd.caption
How to add this condition:
WHERE t.occurence BETWEEN (CURRENT_DATE() - INTERVAL 1 MONTH)
to my request.
+3
source to share
3 answers
BETWEEN
it takes two arguments, a start point and an end point. If the end point is the current time, you have two options:
- Usage
BETWEEN
:
WHERE t.occurence BETWEEN (CURRENT_DATE() - INTERVAL 1 MONTH) AND NOW()
- Using a simple comparison operator:
WHERE t.occurence >= (CURRENT_DATE() - INTERVAL 1 MONTH)
0
source to share