0

我的问题是:

我有 3 张桌子

Workers_Day, Workers_Night,Total

workers_Day表中:

ID, Name, Day_one, Day_two

workers_Night表中:

ID, Name, night_one, night_two

字段将填写100缺席且1正在工作)

TOTAL

ID, Name, Total_days_working, Total_nights_Working, Total

我想将表 1 和 2 中的数据插入到表 3 中。我做了这样的查询,但它不起作用

insert into total (Id, name, Total_days_working, Total_nights_working, Total)
Select id,name,
IIf([day_one]>0,1,0)+IIf([day_two]>0,1,0) as day_workings,
IIf([night_one]>0,1,0)+IIf([night_two]>0,1,0) as Total_nights_working,
Total_days_working+Total_nights_working AS Total
From Workers_day,Workers_night
Where Workers_day.id = Workers_night.id

条件并不总是正确的..

有时表中有不同的工作人员,但是当 ID 为“3”的工作人员“John”在两个表中时问题就开始了(白天,晚上)

4

2 回答 2

0

在这一行:

IIf([day_night]>0,1,0)+IIf([day_night]>0,1,0) as Total_nights_working,

该列day_night不存在。我想你的意思是night_onenight_two

于 2013-07-22T15:33:23.047 回答
0

您的代码中有 2 个错误

正确的是:

insert into total (Id, name, Total_days_working, Total_nights_working, Total)
Select Workers_day.id,Workers_day.name,
IIf([day_one]>0,1,0)+IIf([day_two]>0,1,0) as Total_days_working,
IIf([night_one]>0,1,0)+IIf([night_two]>0,1,0) as Total_nights_working,
Total_days_working+Total_nights_working AS Total
From Workers_day,Workers_night
Where Workers_day.id = Workers_night.id
于 2013-07-23T09:42:44.767 回答