在SQL中追加查询无法正常工作

时间:2011-07-21 22:01:32

标签: sql ms-access ms-access-2003

INSERT INTO 表2(Customer,Order_Date,Stamp_Date,Travelled_Distance,Units,Country,Comments)

选择

'CustomerFamily' As Customer, 
T1.Order_Date AS Order_Date, 
T1.Stamp_Date AS Stamp_Date, 
T1.Travelled_Distance-T2.Travelled_Distance AS Travelled_Distance, 
T1.Units AS Units, 
'Canada' AS Country, 
'' AS Comments

FROM

Table1 AS T1, 
Table1 AS T2

WHERE

T1.Customer='Jake' And 
T2.Customer='Mike' And 
T2.Order_Date=T1.Order_Date

ORDER BY

T1.Order_Date;

这是我的附加查询,其中有一个计算(对于jake和mike在同一天旅行的日子,它减去了来自jakes的mikes旅行距离)

问题是它完成所有计算并将其放入表2中,但每行计算有两行相同。

为什么重复两次?我无法发现错误

1 个答案:

答案 0 :(得分:2)

尝试

SELECT DISTINCT 'CustomerFamily' As Customer, 
T1.Order_Date AS Order_Date, 
T1.Stamp_Date AS Stamp_Date, 
T1.Travelled_Distance-T2.Travelled_Distance AS Travelled_Distance, 
T1.Units AS Units, 
'Canada' AS Country, 
'' AS Comments