Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Day Frequency in week Calc

Author  Topic 

Rheinhardt
Yak Posting Veteran

66 Posts

Posted - 2011-11-15 : 08:46:02
HI,

I have the following data:

Date by Day,Product,Customer,qty
14/11/2011,ProdA,Costb,10
14/11/2011,ProdA,Costb,15
16/11/2011,Prodb,Costb,10


Thereore in week 14/11-19/11 there was 2 deliveries...2 days in the week.

I need too calculate how many times (frequency) a delivery was made by week.So how many days in a week was there a delievry.(By Customer)

I have a Week table as well:

Weeknr,weekstartdate,weekenddate

Please help

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-11-15 : 08:52:56
select t.customer, w.weeknbr, num = count(*), NumDays = count(distinct t.date)
from tbl t
join weektbl w
on t.date between w.weekstartdate and w.weekenddate
group by t.customer, w.weeknbr

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Rheinhardt
Yak Posting Veteran

66 Posts

Posted - 2011-11-15 : 09:44:06
Thanks
Go to Top of Page
   

- Advertisement -