There is a table with a history of changing the status of users. It is necessary to display all users whose status has changed from 2 to 5 (for example). The table has the form: id, id_polz, data, status It is desirable either on Oracle, or on MSSQL. Thank you very much in advance!
- oneRespondents on this site put a minus and close questions if they resemble TK. Dear participant, please supplement the question with your own attempts to cope with the task. Thank. - Sasha Chernykh
- select id_polz, prew_status from (select id_polz, lag (status, 1) over (order by) as prew_status from Table_name group by status, id, id_polz having status = 5) as temp_table where prew_status = 2 there were a lot of attempts, I try to make this request for two days. I tried without a subquery, but I can’t make a filter on the column in which lag is calculated, the error of using window functions crashes - Pavel Burunin
- onePavel, usually we do not carry out your tasks for you, but we help to understand. Add to the question the minimum data, your attempt to write a request, the result obtained, what does not suit him, and what the result should have been - Viktorov
- You can add a link with minimal data to sqlfiddle.com - Viktorov
- Using LAG () is the right decision. Build a CTE (WITH section), add LAG (status, 1) to the data, specifying the correct parameters in OVER . And in the main query, just filter by a pair of status and LAG (status) values. - Akina
|