问题描述
亲爱的所有人,
请找到下面的查询和输出.实际上,我们正在联接Sheet1和Sheet2表,并且如果在Sheet1中stpe是'rework'并且在sheet2中step是'External',则结果将显示如下输出.但是,如果有任何一个步骤可用,如此查询中的sheet1.step ="Rework"或Sheet2.Step ="External",如何获取结果.
我想要如下所示的结果
1)
Dear All,
Please find the below query and output.accatuly we are Join the Sheet1 and Sheet2 tables and the result will be displayed as shown below output if stpe is ‘rework’ in Sheet1 and step is ‘External’ in sheet2 . But how to get the result if any one step is available like sheet1.step ="Rework" or Sheet2.Step="External" in this query.
I want the result as shown below
1)
map sheet1.step Sheet2.step
21-147-00021-0000_20110608 Rework
或
2)
OR
2)
map sheet1.step Sheet2.step
21-147-00021-0000_20110608 External
查询
Query
SELECT Sheet1.map, Sheet1.step, Sheet2.step
FROM Sheet1
INNER JOIN Sheet2 ON (Sheet1.mapType = Sheet2.mapType) AND
(Sheet1.map = Sheet2.map) AND
(Sheet1.batch = Sheet2.batch) AND
(Sheet1.area = Sheet2.area)
WHERE (((Sheet1.area)="Completions") AND
((Sheet1.batch)="Michigan") AND
((Sheet1.step)="Rework") AND
((Sheet2.Step)="External"))
GROUP BY Sheet1.map, Sheet1.step, Sheet2.step;
输出
map Sheet1.step Sheet2.step
21-147-00021-0000_20110608 Rework External
[edit]缩进,代码块.重新格式化的查询将变得可读-OriginalGriff [/edit]
[edit]Indentation, code blocks. Reformatted query to be readable - OriginalGriff[/edit]
推荐答案
这篇关于如何使用SQL Server 2005中的和和或运算符联接到表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!