Tested in MS T-SQL 2003
declare @whatever table(
qty int,
saledate datetime
)
insert into @whatever select 1, getdate()
insert into @whatever select 2, dateadd(dd, -1, getdate())
insert into @whatever select 2, dateadd(dd, -2, getdate())
insert into @whatever select 1, dateadd(dd, -3, getdate())
insert into @whatever select 1, dateadd(dd, -4, getdate())
insert into @whatever select 1, dateadd(dd, -5, getdate())
insert into @whatever select 1, dateadd(dd, -6, getdate())
insert into @whatever select 1, dateadd(dd, -7, getdate())
insert into @whatever select 1, dateadd(dd, -8, getdate())
insert into @whatever select 1, dateadd(dd, -9, getdate())
insert into @whatever select 2, dateadd(dd, -10, getdate())
insert into @whatever select 2, dateadd(dd, -11, getdate())
insert into @whatever select 1, dateadd(dd, -15, getdate())
insert into @whatever select 2, dateadd(dd, -16, getdate())
select
qty,
sum(
case
when datediff(dd, saledate, getdate()) between 0 and 7 then 1
else 0
end
) as [Sold in last 7 days],
sum(
case
when datediff(dd, saledate, getdate()) between 0 and 14 then 1
else 0
end
) as [Sold in last 14 days]
from
@whatever
group by
qty
;