Good day.
Thanks in advance to everyone who will be able to help :) I have been working on a task for 2 weeks already. I would be grateful for any thought :) There is a table with records of the form
day id_work count 20130326 1 2 20130327 1 4 20130328 1 2 20130329 1 0 20130330 1 2 20130331 1 3 20130401 1 2 20130402 1 2 20130403 1 1
There are a lot of such records. Example task: you need to find options for 4-day ranges in which count is above 0, i.e. You need a query that would output from the data in this table:
day1 day2 id_work 20130330 20130402 1 20130331 20130403 1
And with a 3-day range, these options are:
day1 day2 id_work 20130326 20130328 1 20130330 20130401 1 20130331 20130402 1 20130401 20130403 1
The principle of the request. Say need 3-day ranges.
Takes the first record 20130326, looks - count is greater than 0, this is 1 day of the range. Then it takes the next entry 20130327, it looks - count is greater than 0. This is the 2 day range. Then it takes the next entry 20130328, it looks - count is greater than 0. This is the 3 day range. 3 days to eat, then output
20130326 20130327 1
Then we begin with the entry 20130327. It takes the first entry 20130327, it looks - count is greater than 0, this is 1 day of the range. Then it takes the next entry 20130328, it looks - count is greater than 0. This is the 2 day range. Next, it takes the next entry 20130329, it looks - aha, the count is 0. All this range no longer needs to be output.
Then we begin with the entry 20130328. It takes the first entry 20130328, it looks - count is greater than 0, this is 1 day of the range. Next, it takes the next entry 20130329, it looks - aha, the count is 0. This range does not need to be output.
And so on. Here without variables and nested queries in any way. Already the whole brain broke itself)) Is it possible to organize a request that would draw the necessary conclusions? Thank.