主题:查询的速度问题
SELECT
(CASE LeaveApply.LeaveCode WHEN 5 THEN DayoffDaySet.DayoffDays
WHEN 4 THEN DayoffDaySet.OutdoorDays
WHEN 3 THEN DayoffDaySet.RestDays
WHEN 2 THEN DayoffDaySet.HolidayDays
ELSE NULL END) AS LeaveDays
FROM LeaveApply
INNER JOIN
(
SELECT LeaveApply.EmployeeID,LeaveApply.ApplyDateTimeFrom,
SUM(DayoffDay) AS DayoffDays,SUM(OutdoorDay) AS OutdoorDays,
SUM(RestDay) AS RestDays,SUM(HolidayDay) AS HolidayDays
FROM AttendDay
LEFT OUTER JOIN
LeaveApply ON AttendDay.EmployeeID=LeaveApply.EmployeeID
WHERE MONTH(AttendDay.AttendDate) = MONTH(2006-6)
GROUP BY LeaveApply.EmployeeID,LeaveApply.ApplyDateTimeFrom
) AS DayoffDaySet ON LeaveApply.EmployeeID=DayoffDaySet.EmployeeID
AND LeaveApply.ApplyDateTimeFrom=DayoffDaySet.ApplyDateTimeFrom
LeaveApply表 + AttendDay表
CASE LeaveApply.LeaveCode WHEN 5 THEN 求 AttendDay.DayoffDay 的和
WHEN 4 THEN 求 AttendDay.OutdoorDay 的和
WHEN 3 THEN 求 AttendDay.RestDay 的和
WHEN 2 THEN 求 AttendDay.HolidayDay 的和
这样查询速度很慢,询求更快的方法
(CASE LeaveApply.LeaveCode WHEN 5 THEN DayoffDaySet.DayoffDays
WHEN 4 THEN DayoffDaySet.OutdoorDays
WHEN 3 THEN DayoffDaySet.RestDays
WHEN 2 THEN DayoffDaySet.HolidayDays
ELSE NULL END) AS LeaveDays
FROM LeaveApply
INNER JOIN
(
SELECT LeaveApply.EmployeeID,LeaveApply.ApplyDateTimeFrom,
SUM(DayoffDay) AS DayoffDays,SUM(OutdoorDay) AS OutdoorDays,
SUM(RestDay) AS RestDays,SUM(HolidayDay) AS HolidayDays
FROM AttendDay
LEFT OUTER JOIN
LeaveApply ON AttendDay.EmployeeID=LeaveApply.EmployeeID
WHERE MONTH(AttendDay.AttendDate) = MONTH(2006-6)
GROUP BY LeaveApply.EmployeeID,LeaveApply.ApplyDateTimeFrom
) AS DayoffDaySet ON LeaveApply.EmployeeID=DayoffDaySet.EmployeeID
AND LeaveApply.ApplyDateTimeFrom=DayoffDaySet.ApplyDateTimeFrom
LeaveApply表 + AttendDay表
CASE LeaveApply.LeaveCode WHEN 5 THEN 求 AttendDay.DayoffDay 的和
WHEN 4 THEN 求 AttendDay.OutdoorDay 的和
WHEN 3 THEN 求 AttendDay.RestDay 的和
WHEN 2 THEN 求 AttendDay.HolidayDay 的和
这样查询速度很慢,询求更快的方法