除过星期六和星期天,用SQL语句实现一个月应出勤天数的统计

来源:百度知道 编辑:UC知道 时间:2024/06/12 19:44:18

我觉得应该有个类似万年历的日历表,保存一段连续的日期。这样就可以方便的用语句查任意有效月份周六周日以外的总天数。比如查2008年8月:
select sum(case datepart(weekday,日期)when 1 then 0 when 7 then 0 else 1 end) from 日历 where datepart(year,日期) = 2008 and datepart(month,日期) = 8

select sum (出勤) as 出勤总天数 from table_name
where 星期=('一','二','三','四','五')

出勤总天数、星期是你的数据库表中的列名

select sum(出勤)
from table_name
where 出勤 = 'y'
and day in (1,2,3,4,5)

我们设出勤为'y',未出勤为'n'

你要把你表的结构说一下,有哪些字段,存储哪些数据。光一个问题,让别人怎么帮你想呢?