我需要显示一份报告,该报告将显示每周的培训课程报告..从星期一到星期六的某个时间星期日,每天的参加者人数。 我想sql查询来完成这个任务。 例如。如何在两个不同日期之间获得日期(星期一,星期二.....)?
code days mon tues Wed thurs fri sat sun
10001 3 22 22 22 0 0 0 0
10002 5 10 10 10 10 10 0 0 and so on....
这里没有。的参与者在该训练课程的所有日期内都是相同的。
更新查询
.....................我的查询按照@competent_tech建议.......... ...............
CREATE VIEW SessionDOW
AS
SELECT tcapp_id,title,
case when programtype=1 then 'YP' else 'SP' end programtype,
case when NonResidential=2 then 'Res' else 'Non Res.' end nonresidential,duration,
fromdate,TODATE,
Training_Calendar.Participents,
StartDOW = DATEPART(weekday, FromDate) ,
EndDOW = DATEPART(weekday, FromDate)+Duration -1,
weekenddate=DATEPART(d,CONVERT(date,'12-12-2011'))+6
FROM Training_Calendar
GO
select * from sessiondow
CREATE VIEW SessionDays
AS
SELECT SessionDOW.*,
MON = CASE WHEN (2 BETWEEN StartDOW AND EndDOW) OR (EndDow >= 2 + 7) THEN Participents ELSE 0 END ,
TUE = CASE WHEN (3 BETWEEN StartDOW AND EndDOW) OR (EndDow >= 3 + 7) THEN Participents ELSE 0 END ,
WED = CASE WHEN (4 BETWEEN StartDOW AND EndDOW) OR (EndDow >= 4 + 7) THEN Participents ELSE 0 END ,
THURS = CASE WHEN (5 BETWEEN StartDOW AND EndDOW) OR (EndDow >= 5 + 7) THEN Participents ELSE 0 END ,
FRI = CASE WHEN (6 BETWEEN StartDOW AND EndDOW) OR (EndDow >= 6 + 7) THEN Participents ELSE 0 END ,
SAT = CASE WHEN (7 BETWEEN StartDOW AND EndDOW) OR (EndDow >= 0 + 7) THEN Participents ELSE 0 END,
SUN = CASE WHEN (1 BETWEEN StartDOW AND EndDOW) OR (EndDow >= 1 + 7) THEN Participents ELSE 0 END
FROM SessionDOW
GO
SELECT e.*
FROM SessionDays e INNER JOIN Training_Calendar a ON e.tcapp_id = a.TCApp_Id
GROUP BY e.TCApp_Id,e.title,
e.programtype,
e.nonresidential,e.duration,
e.Participents,
e.StartDOW ,
e.EndDOW,sun,MON,tue,wed,thurs,fri,SAT,e.FromDate,e.todate,e.weekenddate
这给我从12月12日以下结果
tcapp_id title programtype nonresidential duration fromdate TODATE Participents StartDOW EndDOW weekenddate MON TUE WED THURS FRI SAT SUN
2011-12/CHD-10001 testing SP Res 10 2011-12-05 2011-12-14 60 2 11 18 60 60 60 60 60 60 60
2011-12/CIT-10001 Training of Palak Technical Officer YP Res 2 2011-12-13 2011-12-14 45 3 4 18 0 45 45 0 0 0 0
2011-12/SIRD-10001 Induction Level Training Programme for JE's of MESCT YP Res 4 2011-12-12 2011-12-15 25 2 5 18 25 25 25 25 0 0 0
2011-12/SIUD-10001 Extempore Leadership Skills Workshop SP Non Res. 5 2011-12-14 2011-12-18 35 4 8 18 0 0 35 35 35 35 35
2011-12/SIUD-10002 fdgd YP Res 6 2011-12-15 2011-12-20 80 5 10 18 80 80 0 80 80 80 80
这里一周的开始和结束,从12月18日,但训练开始5月12日,并于14日结束,但接下来的几天( 15,16,17,18)显示参与者的价值。请帮忙。
这完全取决于数据库的结构。 – ThePower
哪个数据库? – Johan