我有以下问题。 我想根据查找表从一个表中选择数据。这是简单的部分。 但在结果中我想要一个基于查找表的新列。
这是一个示例场景:
LOOKUP-TABLE
Account|Company|Area|origin|aktive
-----------------------------------
0020200|xqzComp|0100|HK1000|1
0020300|xyzComp|0100|HK2000|0
0020400|xxzComp|0100|HK3000|0
0020500|xbzComp|0100|HK4000|1
DATA-TABLE
Account|Company|Area|State|keyFig1|KeyFig2
-------------------------------------------
0020200|xqzComp|0100|GERM|100.000|200.000
0020400|xxzComp|0100|AUST|210.000|130.000
0020400|xxzComp|0100|GERM|222.000|111.000
0020500|xbzComp|0100|GERM|111.000|212.000
RESULT:
Account|Company|Area|State|keyFig1|KeyFig2|new column
------------------------------------------------------
0020200|xqzComp|0100|GERM|100.000|200.000 |is_HK100
0020500|xbzComp|0100|GERM|111.000|212.000 |not_HK100
字段Account,Company,Area都是内连接的关键字段。 但是如何创建基于查找表
列“原点”的列“新列”非常感谢!
答案 0 :(得分:2)
select Account, Company, Area, State, keyFig1, KeyFig2,
case
when table_2.origin = 'HK1000' then 'is_HK1000'
else 'not_HK1000'
end new_column
from table_1
inner join table_2
on table_1.Account = table_2.Account
and table_1.Company= table_2.Company
and table_1.Area = table_2.Area