My database consists of an entry about once per a month for a number of individuals, identified by ID. Dates are stored in fields titled YEAR and WEEK. I have a binary flag, called BINARY_FLAG. I would like to grab the last week for each individual in a specifc year where the binary flag was on.
My code to pull the initial data is as follows:
select ID, year, week, binary_flag
from my_table
where year = 2000 and
binary_flag = 1
This will return all entries for year 2000 where binary flag is 1. However, there will be multiple entries for many of the individuals, if the binary flag was 1 for numerous weeks. How do I remove all but the last week?
1 Answer