`
zhuyx808
  • 浏览: 123405 次
  • 性别: Icon_minigender_1
  • 来自: 快来看~天上米有灰机
社区版块
存档分类
最新评论

如此视图

SQL 
阅读更多
CREATE  view V_Daily
AS
	
	select top 100 percent PerID 员工编码 
		,pm.name 员工姓名
		, postdate 日期
		, convert(varchar(6),datename(dw,postdate)) 星期
		, convert(varchar(2),(sum(AMusehour)*60+sum(AMuseminute))/60) +':'+ convert(varchar(2),(sum(AMusehour)*60+sum(AMuseminute))%60) 上午耗时
		, convert(varchar(2),(sum(PMusehour)*60+sum(PMuseminute))/60) +':'+ convert(varchar(2),(sum(PMusehour)*60+sum(PMuseminute))%60) 下午耗时
		, convert(varchar(2),( (case when sum(AMusehour) is null then 0 else sum(AMusehour)*60 end) +(case when sum(PMusehour) is null then 0 else sum(PMusehour)*60 end) +(case when sum(AMuseminute) is null then 0 else sum(AMuseminute) end) +(case when sum(PMuseminute) is null then 0 else sum(PMuseminute) end) )/60)+':'+convert(varchar(2),( (case when sum(AMusehour) is null then 0 else sum(AMusehour)*60 end) +(case when sum(PMusehour) is null then 0 else sum(PMusehour)*60 end) +(case when sum(AMuseminute) is null then 0 else sum(AMuseminute) end) +(case when sum(PMuseminute) is null then 0 else sum(PMuseminute) end) )%60) 总耗时  
	from 
		(select 
			convert(varchar(10),updateDate,120) postdate
			, PerID
			, amPm
			, (case when amPm='am' then sum(usehour) end) AMusehour
			, (case when amPm='am' then sum(useminute) end) AMuseminute
			, (case when amPm='pm' then sum(usehour) end) PMusehour
			, (case when amPm='pm' then sum(useminute) end) PMuseminute  
		from Daily 		group by updateDate,PerID,amPm 
		) D,pm 
	where D.perID=pm.id
	group by postdate,PerID,pm.name
	order by postdate desc


一个视图就好比一个存储过程~


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics