我在 MS Access 2010 中有两个表:
部分登出表:
PART_ID DRAWN_DATE LOCATION_ID
C0001 07/29/2013 501
C0002 07/29/2013 604
C0003 08/01/2013 703
C0004 08/01/2013 807
C0005 08/02/2013 505
C0006 08/02/2013 602
C0007 08/02/2013 707
C0008 08/03/2013 802
C0009 08/03/2013 803
C0001 10/01/2013 605
C0002 10/02/2013 704
C0004 10/05/2013 806
零件退货表:
PART_ID RETURN_DATE LOCATION_ID
C0001 09/04/2013 STORE
C0002 09/05/2013 STORE
C0004 09/10/2013 STORE
C0007 09/12/2013 STORE
C0008 09/13/2013 STORE
C0002 10/03/2013 STORE
这是我想要的结果:
PART_ID DRAWN_DATE LOG-OUT LOCATION RETURN_DATE RETURN LOCATION
C0001 07/29/2013 501 09/04/2013 STORE
C0001 10/01/2013 605
C0002 07/29/2013 604 09/05/2013 STORE
C0002 10/02/2013 704 10/03/2013 STORE
C0003 08/01/2013 703
C0004 08/01/2013 807 09/10/2013 STORE
C0004 10/05/2013 806
C0005 08/02/2013 505
C0006 08/02/2013 602
C0007 08/02/2013 707 09/13/2013 STORE
C0008 08/03/2013 802 10/03/2013 STORE
C0009 08/03/2013 803
但我只能得到这个:
PART_ID DRAWN_DATE LOG-OUT LOCATION RETURN_DATE RETURN LOCATION
C0001 07/29/2013 501 09/04/2013 STORE
C0001 10/01/2013 605 `09/04/2013 STORE`
C0002 07/29/2013 604 09/05/2013 STORE
`C0002 07/29/2013 604` 10/03/2013 STORE
C0002 10/02/2013 704 `09/05/2013 STORE`
`C0002 10/02/2013 704 10/03/2013 STORE`
C0003 08/01/2013 703
C0004 08/01/2013 807 09/10/2013 STORE
C0004 10/05/2013 806 `09/10/2013 STORE`
C0005 08/02/2013 505
C0006 08/02/2013 602
C0007 08/02/2013 707 09/13/2013 STORE
C0008 08/03/2013 802 10/03/2013 STORE
C0009 08/03/2013 803
在我写下:
SELECT L.PART_ID, L.DRAWN_DATE, L.LOCATION_ID AS [LOG-OUT LOCATION], R.RETURN_DATE, R.LOCATION_ID AS RETURN_LOCATION FROM (SELECT * FROM [PART LOG-OUT] ORDER BY PART_ID) AS L LEFT JOIN (SELECT * FROM [PART RETURN] ORDER BY PART_ID) AS R ON L.PART_ID = R.PART_ID ORDER BY L.PART_ID, L.DRAWN_DATE, R.RETURN_DATE;
有人可以纠正我吗?谢谢!