T
T
TechNOIR2019-09-11 16:27:40
MySQL
TechNOIR, 2019-09-11 16:27:40

MySQL. How to query for date range?

Hello.
There is a request like this:

SET @mydate='2019-05-15 22:00:00';
SELECT COUNT(*) AS count,@mydate AS mydate FROM(
SELECT * FROM ticket th WHERE th.start_time < @mydate GROUP BY tid DESC
) AS t2 WHERE t2.state NOT IN (2,3,9) AND t2.queue = 1

I get the number of tickets whose start_time date is less than the one declared in mydate and where state is not equal to 2,3,9 and queue is equal to 1. The
request works if we substitute a specific date. In response, I get:
count mydate
235 2019-05-15 22:00:00
Is it possible to somehow reformulate the query to get information for a month, let's say? To get in response, for example,
count mydate
231 2019-05-1 22:00:00
232 2019-05-2 22:00:00
233 2019-05-3 22:00:00
234 2019-05-4 22:00 :00
238 2019-05-5 22:00:00
245 2019-05-6 22:00:00
.....
280 2019-05-31 22:00:00
Please tell me if this is possible. thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaliy K, 2019-09-13
@revenger

where `datetime` BETWEEN '2019-04-01' and '2019-06-01'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question