I am trying to find an appropriate solution to the following problem: I have an activity-tracking database and I want to get the status at a specific date (ex: 11-Sept)
| Activity | Status | Date |
|---|---|---|
| 100 | Done | 12-Sept |
| 100 | In prog | 10-Sept |
| 110 | In prog | 12-Sept |
| 110 | In prog | 09-Sept |
| 110 | New | 08-Sept |
My current query is: select * from table where Date <= 11-Sept My current output is:
| Activity | Status | Date |
|---|---|---|
| 100 | In prog | 10-Sept |
| 110 | In prog | 09-Sept |
| 110 | New | 08-Sept |
Problem is I want to limit to only 1 row (newest date) for each activity code. Desired output is:
| Activity | Status | Date |
|---|---|---|
| 100 | In prog | 10-Sept |
| 110 | In prog | 09-Sept |
BUT...
I can't user group by, having or distinct, so the following solutions are not acceptable:
select distinct Name
from table
where Date <= 11-Sept
select name, max(date)
from table
where Date <= 11-Sept
group by name
Basically.. I can only use the where clause
Anyone has an idea?
Desired output is:
| Activity | Status | Date |
|---|---|---|
| 100 | In prog | 10-Sept |
| 110 | In prog | 09-Sept |
To be mentioned: the format of the date here is simplified
11-Septis a string, not a date and can't be sorted in date order. What doesDateactually contain?WHEREclause you need to show us the exact query that this will slot into. Not just some approximation to it. As it will need to be a sub query correlated to the outer query that you have not shown us