Can anyone help with the below SQL. I'm trying to get the top 5 customers for the last 7 days. I've tried to do it as shown below but it doesn't like my ORDER BY statement in the sub select statement. Any way I can get around this?
Thanks in advance.
select top 5 * from
(select c.companyname as companyname, sum(j.cost) as cost
from job j
inner join customer c
on j.cus_guid = c.guid
where j.duedate >= dateadd(day,-7,getdate()) and
j.duedate < dateadd(day,+1,getdate())
group by c.guid,c.companyname,j.cost
order by cost desc
) as data