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
笔误,更正
--早于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'
--早于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'
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)