【发布时间】:2015-03-03 02:04:56
【问题描述】:
我有一个包含以下字段的表:
- 访问 ID
- CPCCID
- 日期
- Time_IN
- 超时
- 课程
- LA_CPCCID
有 3 个会话,9-12、12-3 和 3-6。
我需要一个脚本来计算访问者最多的会话。
我有这个附加的代码,它将确定会话 # 和最大计数:
select Time_In ,
CASE
When cast(Time_In as time) >'12:00:00' and cast(Time_In as time) <='15:00:00' /* and date = cast(GETDATE() as date)*/ then 'Session 2'
when cast(Time_In as time) >'3:00:00' and cast(Time_In as time)<= '6:00:00' /*and date = cast(GETDATE() as date)*/ then 'Session 3'
else 'Session 1'
end "sessions"
from Lab_Visits2;
select max(visit.cnt)
from
(select course, count(course) cnt
from Lab_Visits2
group by Course) visit;
【问题讨论】: