Microsoft Access查询,在列之间匹配值

时间:2019-03-16 02:39:23

标签: ms-access access-vba ms-access-2010

我对Access SQL比较陌生。我使用在线资源尝试了代码,但是每次尝试运行时都会显示错误。

我最初是在Excel中创建的应用程序,即工作表1

Job   Starting Date     Operation              Finish Date   Run Quality 
1     2/3/2019              abc                  5/3/2019          3
1     2/3/2019              bdc                  5/3/2019          3
1     2/3/2019              adc                  5/3/2019          3
1     2/3/2019              edc                  5/3/2019          3
2     3/3/2019              abc                  7/3/2019          4
2     3/3/2019              edc                  7/3/2019          4
2     3/3/2019              adc                  7/3/2019          4

我想创建与此相似的

Job   Starting Date abc     bdc        adc   edc    Run Quality     Finish Date
1     2/3/2019      Done    Done       Done  Done    3                5/3/2019
2     3/3/2019      Done    Progress   Done  Done    4                7/3/2019

我最初是从几个领域开始的

Job abc bdc adc edc  Run Quality 
1   abc bdc adc edc     3
2   abc -   adc edc     4

代码:

SELECT *
FROM 
(
SELECT Job,Operation,Run Quality FROM [OperationTable]
)SRC
PIVOT
(
SUM(Run Quality)
FOR Job IN ([abc],[bdc],[adc],[edc])
)PIV
ORDER BY Job

Excel图片 Input Table & Required Output 如果有人提出他们的宝贵意见,那将非常有用。

1 个答案:

答案 0 :(得分:1)

因此,如果CROSSTAB中的字段返回Null,则显示“进度”,否则显示“完成”。考虑:

查询1:

TRANSFORM First(Table1.Operation) AS FirstOfOperation
SELECT Table1.Job, Table1.StartingDate, Table1.FinishDate, Table1.RunQuality
FROM Table1
GROUP BY Table1.Job, Table1.StartingDate, Table1.FinishDate, Table1.RunQuality
PIVOT Table1.Operation In ("abc","bdc","adc","edc");

Query2:

SELECT Job, StartingDate, FinishDate, RunQuality,
IIf([abc] Is Null,"Progress","Done") AS abcStatus, 
IIf([adc] Is Null,"Progress","Done") AS adcStatus, 
IIf([bdc] Is Null,"Progress","Done") AS bdcStatus, 
IIf([edc] Is Null,"Progress","Done") AS edcStatus
FROM Query1;