A
A
Alexander2020-06-19 16:12:59
MySQL
Alexander, 2020-06-19 16:12:59

How to compare data for a period and exclude unnecessary values?

There is a table

id | lid | status | date1
| 44 | 2 | 01/04/2020
2 | 44 | 1 | 01/06/2020
3 | 66 | 3 | 01/09/2020
4 | 66 | 2 | 01/02/2020
5 | 77 | 4 | 01/04/2020
6 | 77 | 2 | 01/01/2020
7 | 77 | 3 | 01/03/2020
8 | 88 | 1 | 01/08/2020
9 | 88 | 2 | 01/06/2020

id - unique
lid - the entity of which is set status to a specific date

How to select from the database the number of lids that in a certain PERIOD were in a certain status for more than a certain period (the status did not change, of course)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2020-06-19
@Casufi

You haven't formalized the task. What does "were in the status of a certain period" mean? If from the first to the third day we received three entries with lead 2 and status 2, is this our entry? The second option is if, starting from this post, we received two more posts with this lead and both had the same status.
The first is solved in MySQL, the second by window functions in PostgreSQL

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question