求一解决思路。

fuzijing 2009-11-22 03:12:37
数据库记录了1-12月份每个员工的加班情况,
记录表的结构:加班记录id --加班员工id --加班时间
现在想得到一份统计列表,
前台页面结构如下,
月份 实加班 应加班 存休
1月份 4 ?天
2月份 4 ?天
3月份 4 ?天
4月份 4 ?天
5月份 4 ?天
6月份 4 ?天
7月份 4 ?天
8月份 4 ?天
9月份 4 ?天
10月份 4 ?天
11月份 4 ?天
12月份 4 ?天

求一个比较好的方式,得到员工1-12月份的实加班情况统计。
...全文
122 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
wjw6200 2009-11-22
  • 打赏
  • 举报
回复
楼主需求不明确.. 你的加班时间字段是要表达什么信息?
是加班发生在哪一天?还是加班了几个小时或者是几天?

如果是加班时间是datetime类型(加班发生在哪一天) 那6楼完全正解 。
如果加班时间是数值类型的 那一楼的正解 ,也就是说肯定要有时间字段 ,
Taiyangchen 2009-11-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wuyq11 的回复:]
按月分组统计
select
  '数量' as ' ',
  sum(case month(日期) when 1 then 数量 else 0 end) as [一月],
  sum(case month(日期) when 2 then 数量 else 0 end) as [二月],
  sum(case month(日期) when 3 then 数量 else 0 end) as [三月],
  sum(case month(日期) when 4 then 数量 else 0 end) as [四月]
from tb
http://topic.csdn.net/u/20080829/13/3d1eabe0-c558-4f8c-a373-b060af66e2eb.html
[/Quote]

right
hy_lihuan 2009-11-22
  • 打赏
  • 举报
回复
一个sql语句就可以解决的问题需要什么解决思路?
难道你还打算使用临时表来储存你的统计数据加快检索时间?
  • 打赏
  • 举报
回复
你的数据已有,那么就按你想显示的格式显示每月情况详表
最后表格一列显示累计就可以了
这个显示1使用模板2我觉得直接后台输出更方便更直接些
http://blog.csdn.net/xianfajushi/archive/2009/07/22/4371397.aspx
波导终结者 2009-11-22
  • 打赏
  • 举报
回复
declare @table table(加班员工id varchar(10),加班时间 datetime)

insert into @table values('1','2009-01-01')
insert into @table values('1','2009-01-02')
insert into @table values('1','2009-02-01')
insert into @table values('1','2009-03-01')
insert into @table values('1','2009-04-01')
insert into @table values('1','2009-05-01')
insert into @table values('1','2009-06-01')
insert into @table values('1','2009-07-01')
insert into @table values('1','2009-08-01')
insert into @table values('1','2009-09-01')
insert into @table values('1','2009-10-01')
insert into @table values('1','2009-11-01')
insert into @table values('1','2009-12-01')
insert into @table values('2','2009-12-01')

select
case month(加班时间) when 1 then '一月'
when 2 then '二月'
when 3 then '三月'
when 4 then '四月'
when 5 then '五月'
when 6 then '六月'
when 7 then '七月'
when 8 then '八月'
when 9 then '九月'
when 10 then '十月'
when 11 then '十一月'
when 12 then '十二月' end as 月份,
sum(1) as 加班次数
from @table
where 加班员工id='1'
group by month(加班时间)
红街咖啡 2009-11-22
  • 打赏
  • 举报
回复
上面的只是一个参考。你改下你想要的就行了
红街咖啡 2009-11-22
  • 打赏
  • 举报
回复

--by Month
declare @time1 datetime, @time2 datetime
set @time1='2009-11-14'
set @time2='2009-11-14'
select convert(varchar(7),k.rn+@time1-1,120) as Date ,isnull(sum(GetMoney),0) as GetMoney
from AgentAmountLog a right join
(select ROW_NUMBER() over(order by getdate()) as rn from sys.columns a ,sys.columns b) k
on DATEDIFF(DAY,a.LogTime,k.rn+@time1-1)=0
where k.rn+@time1-1<=@time2
group by convert(varchar(7),k.rn+@time1-1,120)
order by Date
AngleBabyHong 2009-11-22
  • 打赏
  • 举报
回复
学习
wuyq11 2009-11-22
  • 打赏
  • 举报
回复
按月分组统计
select
'数量' as ' ',
sum(case month(日期) when 1 then 数量 else 0 end) as [一月],
sum(case month(日期) when 2 then 数量 else 0 end) as [二月],
sum(case month(日期) when 3 then 数量 else 0 end) as [三月],
sum(case month(日期) when 4 then 数量 else 0 end) as [四月]
from tb
http://topic.csdn.net/u/20080829/13/3d1eabe0-c558-4f8c-a373-b060af66e2eb.html
ivws_19 2009-11-22
  • 打赏
  • 举报
回复
需要一个日期字段date吧
select 加班员工id,sum(加班时间) from table group by 加班员工id,datepart(month,date)
这样得到员工每个月的加班时间

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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