Skip to content

Tag: window-functions

Getting values based on other column

I have the following data in SQL. Is there a way using SELECT QUERY that we can replace the NULL values in DATE column based on the REF values? Like replace the NULL values with the first available date for matching REF value, without making any change to the database. Expected Result Answer You can do it wit…

SQL to find records with last 3 same status

I have the following tasks table: I need to run a query that returns only the types which their last 3 tasks finished with status “FAILED”. How can I do this? Should I use a window function? Thanks Answer You can use aggregation and filtering after using row_number() to get the last three rows: Ac…