一个麻烦的统计sql语句,用到了分区试图(t_workcheck联合了26张表)。这样查询的时用到表的数量超过了256个。不知道哪位能够给简化一下
hblzq 2007-09-26 03:23:41 select t_Department.DepName,t_WorkGroup.GroupName,t.name, t.WorkID,t_WorkType.WorkTypeName,
(select count(*) from t_WorkCheck where t_WorkCheck.EmployeID = t.EmployeID and BanCID = '0' and CheckDate between '2007-09-21' and '2007-09-25') as BanC0,
(select sum(WorkMinutes)+sum(PatchTime) from t_WorkCheck where t_WorkCheck.EmployeID = t.EmployeID and BanCID = '0' and CheckDate between '2007-09-21' and '2007-09-25') as BanC02,
(select CONVERT(decimal(10,2),avg(convert(float,WorkMinutes))+avg(convert(float,PatchTime))) from t_WorkCheck where t_WorkCheck.EmployeID = t.EmployeID and BanCID = '0' and CheckDate between '2007-09-21' and '2007-09-25') as BanC03, (select count(*) from t_WorkCheck where t_WorkCheck.EmployeID = t.EmployeID and BanCID = '1' and CheckDate between
'2007-09-21' and '2007-09-25') as BanC4,
(select sum(WorkMinutes)+sum(PatchTime) from t_WorkCheck where t_WorkCheck.EmployeID = t.EmployeID and BanCID = '1' and CheckDate between '2007-09-21' and '2007-09-25') as BanC42,
(select CONVERT(decimal(10,2),avg(convert(float,WorkMinutes))+avg(convert(float,PatchTime))) from t_WorkCheck where t_WorkCheck.EmployeID = t.EmployeID and BanCID = '1' and CheckDate between '2007-09-21' and '2007-09-25') as BanC43,
(select count(*) from t_WorkCheck where t_WorkCheck.EmployeID = t.EmployeID and BanCID = '2' and CheckDate between '2007-09-21' and '2007-09-25') as BanC8,
(select sum(WorkMinutes)+sum(PatchTime) from t_WorkCheck where t_WorkCheck.EmployeID = t.EmployeID and BanCID = '2' and CheckDate between '2007-09-21' and '2007-09-25') as BanC82,
(select CONVERT(decimal(10,2),avg(convert(float,WorkMinutes))+avg(convert(float,PatchTime))) from t_WorkCheck where t_WorkCheck.EmployeID = t.EmployeID and BanCID = '2' and CheckDate between '2007-09-21' and '2007-09-25') as BanC83,
(select count(*) from t_WorkCheck where t_WorkCheck.EmployeID = t.EmployeID and BanCID = '3' and CheckDate between '2007-09-21' and '2007-09-25') as BanCn,
(select sum(WorkMinutes)+sum(PatchTime) from t_WorkCheck where t_WorkCheck.EmployeID = t.EmployeID and BanCID = '3' and CheckDate between '2007-09-21' and '2007-09-25') as BanCn2,
(select CONVERT(decimal(10,2),avg(convert(float,WorkMinutes))+avg(convert(float,PatchTime))) from t_WorkCheck where t_WorkCheck.EmployeID = t.EmployeID and BanCID = '3' and CheckDate between '2007-09-21' and '2007-09-25') as BanCn3,
(select count(*) from t_WorkCheck where t_WorkCheck.EmployeID = t.EmployeID and CheckDate between '2007-09-21' and '2007-09-25') as total,
(select sum(WorkMinutes)+sum(PatchTime) from t_WorkCheck where t_WorkCheck.EmployeID = t.EmployeID and CheckDate between '2007-09-21' and '2007-09-25') as total2,
(select CONVERT(decimal(10,2),avg(convert(float,WorkMinutes))+avg(convert(float,PatchTime))) from t_WorkCheck where
t_WorkCheck.EmployeID = t.EmployeID and CheckDate between '2007-09-21' and '2007-09-25') as total3 from (select distinct EmployeID,WorkID,Name,DepID,WorkTypeID,WorkGroupID,ShowOrder from t_Employe where DelFlag = '0' and CardID <> '' ) t
left join t_Department on t.DepID=t_Department.DepID left join t_WorkType on t.WorkTypeID = t_WorkType.WorkTypeID left join t_WorkGroup on t.DepID = t_WorkGroup.DepID and t.WorkGroupID = t_WorkGroup.GroupID order by
t.DepID,t.WorkGroupID,t.ShowOrder