Apologies in advance if I am asking in the wrong forum.
I am trying to get the first attribute value for each ID in my table based on the ID’s starting week. When using the min() function on weekkey, my query is returning two values if an ID has more than one attribute.
Drop table if Exists table1
CREATE TABLE table1 (
IDNumber INT NOT NULL,
Attribute VARCHAR(30) NOT NULL,
WeekKey INT NOT NULL,
INSERT INTO table1
(IDNumber, Attribute, WeekKey)
Select IDNumber, Attribute, Min(WeekKey) StartWeek
Group by IDNumber, Attribute
Order by IDNumber, Attribute
My goal output would be:
My current output is:
Does anyone have an idea how to accomplish my goal without too many extra steps?