UPDATE Tab_Checksum
SET 姓名=[name],
考勤日期=checkdate,
按时上课=(SUM(startclass)
FROM Tab_Check
GROUP BY [name],checkdate),
按时下课=(SUM(finishclass)
FROM Tab_Check
GROUP BY [name],checkdate),
迟到=(SUM(later)
FROM Tab_Check
GROUP BY [name],checkdate),
旷课=(SUM(absenteeism)
FROM Tab_Check
GROUP BY [name],checkdate),
早退=(SUM(startclass)-SUM(finishclass)
FROM Tab_Check
GROUP BY [name],checkdate),)
ORDER BY[name],checkdate
这是我写的,为什么呢,谢谢啦
------解决思路----------------------
--语法明显有问题噢,这样?
UPDATE Tab_Checksum
SET 姓名=[name],
考勤日期=checkdate,
按时上课=(SELECT SUM(startclass)
FROM Tab_Check
GROUP BY [name],checkdate),
按时下课=(SELECT SUM(finishclass)
FROM Tab_Check
GROUP BY [name],checkdate),
迟到=(SELECT SUM(later)
FROM Tab_Check
GROUP BY [name],checkdate),
旷课=(SELECT SUM(absenteeism)
FROM Tab_Check
GROUP BY [name],checkdate),
早退=(SELECT SUM(startclass)-SUM(finishclass)
FROM Tab_Check
GROUP BY [name],checkdate)
------解决思路----------------------
-- 如果Tab_Checksum还没有添加姓名、考勤日期
INSERT INTO Tab_Checksum (姓名,考勤日期,按时上课,按时下课,迟到,旷课,早退)
SELECT [name],
checkdate,
SUM(startclass) startclass,
SUM(finishclass) finishclass,
SUM(later) later,
SUM(absenteeism) absenteeism,
SUM(startclass)-SUM(finishclass) startclass_finishclass
FROM Tab_Check
GROUP BY [name],checkdate
ORDER BY [name],checkdate
-- 如果Tab_Checksum已经有了姓名、考勤日期
UPDATE Tab_Checksum
SET Tab_Checksum.按时上课 = t.startclass,
Tab_Checksum.按时下课 = t.finishclass,
Tab_Checksum.迟到 = t.later,
Tab_Checksum.旷课 = t.absenteeism,
Tab_Checksum.早退 = t.startclass_finishclass
FROM Tab_Checksum,
(
SELECT [name],
checkdate,
SUM(startclass) startclass,
SUM(finishclass) finishclass,
SUM(later) later,
SUM(absenteeism) absenteeism,
SUM(startclass)-SUM(finishclass) startclass_finishclass
FROM Tab_Check
GROUP BY [name],checkdate
) t
WHERE Tab_Checksum.姓名 = t.[name]
AND Tab_Checksum.考勤日期 = t.checkdate