怎么比较时间

yuga 2003-08-19 10:44:59
TimeCardNo MemberId MorningTime OffTime
223 1 2002-8-3 8:30:22 2002-8-3 18:30:22
......

我想知道,一段时间每个人早于8:00上班的的和晚于19:00下班的次数
时间是datetime
总是有问题
...全文
37 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
CrazyFor 2003-08-19
  • 打赏
  • 举报
回复

select memberid
,sum(case when right(convert(char(16),morningtime,120),5)<'08:00' then 1 else 0 end ) [早于8:00上班]
,sum(case when right(convert(char(16),offtime,120),5)>'19:00' then 1 else 0 end ) [晚于19:00下班]
from 表 group by memberid
z5wjz 2003-08-19
  • 打赏
  • 举报
回复
select memberid,count(*)
from yourtable
where datepart(hh,morningtime)<8 and datepart(hh,offtime)>19 and datetime=你的日期
group by memberid
goneaway 2003-08-19
  • 打赏
  • 举报
回复
笔误,更正
--早于8:00上班
select count(*) from table
where substring(convert(nvarchar(20),MorningTime,120),12,8)<'08:00:00'
--晚于19:00下班
select count(*) from table
where substring(convert(nvarchar(20),OffTime,120),12,8)>'19:00:00'
goneaway 2003-08-19
  • 打赏
  • 举报
回复
--早于8:00上班
select count(*) from table
where substring(convert(nvarchar(20),MorningTime,120),12,8)<'08:00:00'
--晚于19:00下班
select count(*) from table
where substring(convert(nvarchar(20),MorningTime,120),12,8)>'19:00:00'
hjb111 2003-08-19
  • 打赏
  • 举报
回复
select *,count(*) 考勤 from yourtable where convert(varchar,108,Morningtime)<'08:00:00' and convert(varchar,108,OffTime)>'19:00:00' and convert(varchar,102,MorningTime)=convert(varchar,108,OffTime)

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧