Похоже, что работает -
tblReleaseNo:
| Release No | Hose Part No | Release Date | Due Date |
|------------|--------------|--------------|------------|
| 1 | Hose 1 | 01/01/2018 | 01/01/2018 |
| 2 | Hose 1 | 01/01/2018 | 01/01/2018 |
| 3 | Hose 2 | 01/01/2018 | 01/01/2018 |
| 4 | Hose 2 | 01/01/2018 | 01/01/2018 |
| 5 | Hose 3 | 01/01/2018 | 01/01/2018 |
NewScrapTble:
| Release No | Inspect Date | scrapamt1 | reason1 | scrapamt2 |
|------------|--------------|-----------|---------|-----------|
| 1 | 01/12/2018 | 10 | | 15 |
| 2 | 12/12/2018 | 15 | | 18 |
| 3 | 01/07/2018 | 12 | | 12 |
| 4 | 01/08/2018 | 14 | | 200 |
| 5 | 01/03/2017 | 22 | | 20 |
SQL:
SELECT [Hose Part No]
, MAX([Inspect Date]) AS Inspect
, LAST(scrapamt1) AS Amount1
, LAST(scrapamt2) AS Amount2
FROM (
SELECT [Hose Part No]
, [Inspect Date]
, scrapamt1
, scrapamt2
FROM tblReleaseNo INNER JOIN NewScrapTble ON
tblReleaseNo.[Release No] = NewScrapTble.[Release No]
)
GROUP BY [Hose Part No]
Финальный стол:
| Hose Part No | Inspect | Amount1 | Amount2 |
|--------------|------------|---------|---------|
| Hose 1 | 12/12/2018 | 15 | 18 |
| Hose 2 | 01/08/2018 | 14 | 200 |
| Hose 3 | 01/03/2017 | 22 | 20 |
Примечание: Я не уверен на 100%, что LAST
правильно, он тянет правильные суммы, но не уверен, что он будет срабатывать на некоторых записях?