Answer the question
In order to leave comments, you need to log in
Is it possible to collect such a request?
Hello!
Can tell you how to make a sql query so that you can get the following (2nd block "Records"):
I.e. there is a table with fields:
id, done(boolean), date(YYYY-MM-DD)
I want to create a query that can give something like this:
date_start, count, date_end
limit 10
Well, how is everything in the "Records" block
Is this possible ?
Thank you!
Answer the question
In order to leave comments, you need to log in
SELECT pairs.startDate, pairs.endDate, pairs.endDate - pairs.startDate + 1 as count FROM
(SELECT t1.date as startDate, MIN(t3.date) as endDate FROM statistics as t1
LEFT JOIN statistics t2 ON t1.date - t2.date = 1 and t2.done = 1
LEFT JOIN statistics as t3 ON t1.date <= t3.date and t3.done = 1
LEFT JOIN statistics as t4 ON t3.date - t4.date = -1 and t4.done = 1
WHERE t1.done = 1 AND ISNULL(t2.date) AND ISNULL(t4.date)
GROUP BY t1.date) as pairs
ORDER BY pairs.startDate
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question