help constructing a select statement
hi captain,
if understand correctly, want data last week of quarter. if so, can use inner join follow:
create table products(id int,name nvarchar(10),quarter int,week int)
go
insert into products values(1,'a',1,1)
go
insert into products values(2,'b',1,2)
go
insert into products values(3,'c',2,1)
go
insert into products values(4,'d',2,2)
go
insert into products values(5,'e',2,3)
go
select a.* from products a
inner join (select quarter as qa,max(week) as qb from products group by quarter) b
on a.quarter=b.qa
where a.quarter=2 and a.week=b.qb
if have more questions, please feel free let me know.
thanks,
yoyo yu
SQL Server > SQL Server Compact
Comments
Post a Comment