Leo Torres
asked on
tSQL multiple date ranges in one query
I need to create table with 3 different time ranges
(ONE) Targets table had TargetID as PK
to
(MANY) Visits table has TargetID
I am getting counts of targets and Business in the visit table..
How could I create it so there is a column for 30 days 60 days and 90 Days
The code below works for 30 days but i want it to have 2 more columns for 60 days and 90 days
any suggestions would be greatly appreciated
Select t.BusinessUnitID, Count(1) as Days30
from dbo.Targets t (nolock)
inner join dbo.VIEW_Visits vv (nolock)
on vv.CreationTime > getdate()-30
and t.TargetID = vv.TargetID
and t.businessUnitID in (9,18,1)
Group by t.BusinessUnitID
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER