我已经待了好几天了,所以卡住了!他们想知道4月份AM,PM和晚会的次数以及会议的总访问次数
即。 月:4月 ct_AM_sess 19,#Visit3 ct_PM_sess 21,#Visit 116 ct_Eve_sess 4,#Visits 23
我试图将它做成Crystal甚至将数据移动到excel。
select resourceid, ApptStart,datename(m,ApptStart) as daymonth,datename(dd,ApptStart) as day,
datename(yy,ApptStart) as year, count(AppointmentsId) As Visits,
CASE WHEN DATEPART(hour, ApptStart) BETWEEN 0 AND 12 THEN 'AM' END AS 'MORNING_SESSION',
CASE WHEN DATEPART(hour, ApptStart) BETWEEN 13 AND 17 THEN 'PM' END AS 'AFTERNOON_SESSION',
CASE WHEN DATEPART(hour, ApptStart) BETWEEN 18 AND 24 THEN 'EVE' END AS 'EVENING_SESSION'
from appointments
where Resourceid = '50' and
datename(m,ApptStart) = 'April' and datename(yy,ApptStart) = '2014' --using timeframe for sample data
and status in ('Arrived','Completed')
group by resourceid, ApptStart,datename(m,ApptStart),datename(dd,ApptStart),datename(yy,ApptStart)
答案 0 :(得分:0)
根据您的需要对您的案例陈述进行分析然后分组,这将为您提供对会话的依据,因为您并没有真正让我们知道如何区分访问和会话
CASE WHEN DATEPART(hour, min(ApptStart)) BETWEEN 0 AND 12 THEN count(distinct appointmentid) END AS 'MORNING_SESSION',
CASE WHEN DATEPART(hour, min(ApptStart)) BETWEEN 13 AND 17 THEN count(distinct appointmentid) END AS 'AFTERNOON_SESSION',
CASE WHEN DATEPART(hour, min(ApptStart)) BETWEEN 18 AND 24 THEN count(distinct appointmentid) END AS 'EVENING_SESSION'