Update
I think there's an easier solution that'll save processing time as well. I could just delete all records that that have status = 'completed' and status = 'ongoing' before completed.
That way I only have to simply query to First_value where status = 'ongoing'.
How would I write that?
I'm working on a database. I have a table with records that are as follows, quotations describe the columns input, the focus of my question is on Date and Status
- Name "Users name is auto populated from CSV"
Location "NC,SC,NJ, ETC"
City "Carthage, Myrtle Beach, ETC"
- Date "Date record was entered is automatically input by SQL when importing CSV in format YEAR-MM-DD"
- Status "Ongoing or Completed are the only two entries"
The Date
column and status
columns are updated regularly.
I need my SELECT DISTINCT
query to return the record by the first date when the Status column = 'Ongoing'. That part, I know how to do. However, whenever a records Status column goes to 'Completed' one day and a new record is added later with the Status as ongoing, I see the first ever record where the Status field = 'Ongoing'.
I attached a visual of what the I'm talking about. I need my query to return the 3rd box from the left and not the first.