2013-06-19 64 views
0

我刚开始使用SQL。数据存储在三个表中。一个例子如下...SQL查询:有条件地从多个列中获取数据

TABLE1

柱:产品系列

TABLE2

柱:位置

表3 intrest的列:

建设厂房

产品类型

forcast2012

forcast2013

forcast2014

forcast2015

如果... 存储在 “位置” 的任何文本值一个给定的文本匹配价值在“建筑工厂”&如果有任何文字价值存储在“产品系列” E给定文本值“产品类型”

然后... 抢在相应的行中的四列“forcast2012,forcast2013,forcast2014,forcast2015”的内容,并建立一个新的匹配由它们组成的表以及它们匹配的“位置”和“产品族”值。

+0

你到目前为止有什么? – Oscar

+0

这是我到目前为止:这是礼貌@Bill Gregg。 – Ben

+0

选择facility.location,ProductFamily.productfamily,[2012年完整单位带有C],[2013年完整单位带有C],[2014年带有整体单位],[2015年带有完整单位],[2016完整单位W/C],[2017全套装备有W/C],[2018全套装备W/C] 从表带 内部连接带上ProductFamily.productfamily =表带。[prod系列] 内部连接装置表带[建筑工厂] = facility.location – Ben

回答

0
select table2.location, table1.productfamily, forcast2012, forcast2013, forcast2014, forcast2015 
from table1 
inner join table3 on table1.productfamily = table3.producttype 
inner join table2 on table3.[building plant] = table2.location