使用相应记录访问选择最大日期

时间:2018-11-09 13:55:43

标签: ms-access ms-access-2010

我正在尝试创建一个查询最新日期的查询并返回相应的值。仅当我具有maxhose part no列且没有其他内容时,才能使用max inspection函数。一旦我添加了scrap amount列,它就会复制hose part no列。我只希望每个软管零件号有一个记录。 以下是发生情况的示例。

Hose Part No Max Inspection Date scrapamt1 scrapamt2 scrapamt3 scrapamt4

enter image description here

enter image description here

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:0)

如果我理解您说的没错,这就是您想要的:

df['group'] = pd.cut(df.value, range(0, highest_size), right=False, labels=labels)

子查询(名为Select * From Table1 Inner Join (Select Table1.[Hose Part No], Max(Table1.[Max Inspection Date]) As [MaxOfMax Inspection Date] From Table1 Group By Table1.[Hose Part No]) As MaxValues On Table1.[Hose Part No] = MaxValues.[Hose Part No] And Table1.[Max Inspection Date] = MaxValues.[MaxOfMax Inspection Date] )用于确定每个MaxValues的最大Max Inspection Date,并将其连接到同一表。

因为您也没有提及表格名称,所以我选择了Hose Part No

答案 1 :(得分:0)

这似乎可行-

tbl发布编号:

| 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是正确的,它提取正确的金额,但不确定是否会在某些记录上跳闸?