如果用2楼的思路来完成,在输入新记录时,用代码寻找之前该工号是否有未完成的记录,有则提示是否用代码同步(也就一个更新查询),就能解决问题。作者: hi-wzj 时间: 2007-9-13 10:49
gju作者: hi-wzj 时间: 2007-9-13 10:52
对7楼程序的修订
查询1的sql语句更改为:
SELECT DMin("[作业日期]","表1","[工号]='" & [工号] & "' and [作业日期]> #" & [作业日期] & "#") AS 结束日期, 表1.工号, 表1.作业日期, 表1.工位能力, IIf(IsNull([结束日期]),DateDiff("d",[作业日期],Format(Now(),"yyyy-mm-dd")),DateDiff("d",[作业日期],[结束日期])) AS 天数
FROM 表1
ORDER BY 表1.工号, 表1.作业日期;作者: zyz218 时间: 2007-9-13 12:02
谢谢WZJ与ANDYMARK的大力支持,在下受益非浅! 作者: andymark 时间: 2007-9-13 12:39
用左联接重写了查询
SELECT c.系统编号, c.工号, c.工位能力, c.作业日期, d.结束日期, IIf(IsNull(d.结束日期),datediff("d",c.作业日期,format(now(),"yyyy-mm-dd")),datediff("d",c.作业日期,d.结束日期)) AS 天数
FROM 表1 AS c LEFT JOIN [SELECT a.系统编号, a.工号, a.工位能力, a.作业日期, min(b.作业日期) AS 结束日期
FROM 表1 AS a INNER JOIN 表1 AS b ON a.工号=b.工号
WHERE b.作业日期>a.作业日期
GROUP BY a.工号, a.系统编号, a.工位能力, a.作业日期
]. AS d ON val(c.系统编号)=val(d.系统编号)
ORDER BY c.工号, c.系统编号;作者: andymark 时间: 2007-9-13 12:40
整合到交叉表
TRANSFORM Sum(e.天数) AS 天数之总计
SELECT e.工号, Sum(e.天数) AS [总计 天数]
FROM [SELECT c.系统编号, c.工号, c.工位能力, c.作业日期, d.结束日期, IIf(IsNull(d.结束日期),datediff("d",c.作业日期,format(now(),"yyyy-mm-dd")),datediff("d",c.作业日期,d.结束日期)) AS 天数
FROM 表1 AS c LEFT JOIN [SELECT a.系统编号, a.工号, a.工位能力, a.作业日期, min(b.作业日期) AS 结束日期
FROM 表1 AS a INNER JOIN 表1 AS b ON a.工号=b.工号
WHERE b.作业日期>a.作业日期
GROUP BY a.工号, a.系统编号, a.工位能力, a.作业日期
]. AS d ON val(c.系统编号)=val(d.系统编号)
ORDER BY c.工号, c.系统编号]. AS e
GROUP BY e.工号
PIVOT e.工位能力;