【发布时间】:2020-10-05 17:47:22
【问题描述】:
我有一个名为 customer 的引用表,它具有 cust_id、cust_name ...,还有其他表具有 cust_name、cust_location ....等等。我需要使用 cust_name 从所有这些表中查找 cust_location。如何在 oracle SQL 中编写查询?
select cust_id, cust_name from customer
from (
select cust_name as cust_location from tb1
union all
select cust_name as cust_location from tbl2
union all
select cust_name as cust_location from tbl3
)
预期结果.......看起来像
【问题讨论】:
-
似乎您需要熟悉
JOIN和与表格相关的“键”(您的问题中没有提供)。 -
除了问题,你为什么要像
cust_name as cust_location那样做?样本数据和预期结果真的很有帮助。 -
请提供样本数据和期望的结果。不清楚您所说的“查找”是什么意思。
-
对于特定的 cust_name,cust_location 应该只出现在这些表之一(tb1,tb2,tb3...)如果它出现在 tb1 中,则 cust_location 的值对于其他表应该为 null .所以我需要通过它所在的表查找并列出 cust_location
-
您希望结果看起来如何?您能否也添加您的预期结果。