日期:2014-05-17 浏览次数:20494 次
create table #tmp(resourceid varchar(30) ,ResourceName varchar(20),Model varchar(20),MfgWeek int ,dataTime decimal(18,2),CoeeGroup varchar(20)) insert into #tmp select '1101260000010000001','TTU-02','UltraFlex',1,10080,'IDLE' UNION ALL select '1101260000010000001','TTU-02','UltraFlex',10,535.74,'DOWN' UNION ALL select '1101260000010000001','TTU-02','UltraFlex',10,1.83,'ENGR' UNION ALL select '1101260000010000001','TTU-02','UltraFlex',10,5405.1,'IDLE' UNION ALL select '1101260000010000001','TTU-02','UltraFlex',10,3215.85,'PROD(Charge)' UNION ALL select '1101260000010000001','TTU-02','UltraFlex',10,919.82,'PROD(Non-Charge)' UNION ALL select '1101260000010000001','TTU-02','UltraFlex',10,1.67,'IDLE' UNION ALL select '1101260000010000001','TTU-02','UltraFlex',11,10080,'IDLE' --drop table #tmp --select * from #tmp select a.resourceid,a.resourcename,a.model,a.mfgweek,cast (datatime/dall as decimal(18,4)) averg,coeegroup from #tmp a, ( select mfgweek,sum(datatime) dall from #tmp group by mfgweek)b where a.mfgweek=b.mfgweek