append query in SQL not working right
INSERT INTO Table2 ( Customer, Order_Date, Stamp_Date, 开发者_运维知识库Travelled_Distance, Units, Country, Comments )
SELECT
'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;
This is my append query that has a calculation in it ( for the days that jake and mike travel on same day it subtracts mikes travel distance from jakes)
the PROBLEM is that it does all the calculation fine and puts it into Table 2 but there is two rows which are the same for every single calculation.
why is it repeating twice? I can't spot the error
Try
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
精彩评论