ITEMCODE
alternatecode
abcd | 1200 |
---|---|
1800 | |
贝尔 | |
11.05 | |
sled | 17.12 |
技术 | |
SELECT itemcode, price
FROM pricing
WHERE itemcode in ('abcd','xxxx','bark','home','sled','tech','bell')
|
|
abcd
select
*
from pricing p
left join alternate_codes ac
on ac.alternate_code = p.itemcode
现在我们将每一行都与其替代品匹配。
coalesce
xxxx | 10.00 |
---|---|
home | |
贝尔 | |
启动 | |
现在选择正确的项目代码。如果定义了备用_codes.itemcode,我们应该使用它,否则我们使用pricing.itemcode。使用 |
SELECT
coalesce(ac.itemcode, p.itemcode) as itemcode,
price
FROM pricing p
LEFT JOIN alternate_codes ac
ON ac.alternate_code = p.itemcode
WHERE coalesce(ac.itemcode, p.itemcode) in ('abcd','xxxx','bark','home','sled','tech','bell')