假设我想将来自不同数据库的 2 个表合并到一个表中,其中包含来自 2 个表的所有数据:
结果看起来像这样:
结果表中的条目是不是多余的,因为保时捷和大众有2个条目?或者我可以只在股票"列中添加值,因为标记"列是明确的?
select * from tableA@"database_link_name"您可以在此处阅读合并语句:https://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm#SQLRF01606
<前><代码>合并到 result_table res使用(选择标记、库存、some_unique_id来自 result_table res2联合所有选择标记、库存、some_unique_id来自 tableA@"database_link_name") diff在 (res.some_unique_id = diff.some_unique_id )当匹配然后更新集 res.mark = diff.mark,res.stock = diff.stock当不匹配时插入(res.mark,资源库存,res.some_unique_id)价值观(差异标记,差异股票,diff.some_unique_id);Hypothetically I want to merge 2 tables from different databases into one table, which includes all the data from the 2 tables:
The result would look like something like this:
Aren't the entries in the result table redundant, because there are 2 entries with Porsche and VW? Or can I just add the values in the column 'stock' because the column 'Mark' is explicit?
select * from tableA@"database_link_name"you can read about merge statement here: https://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm#SQLRF01606
merge into result_table res
using (select mark, stock, some_unique_id
from result_table res2
union all
select mark, stock, some_unique_id
from tableA@"database_link_name") diff
on (res.some_unique_id = diff.some_unique_id )
when matched then
update set res.mark = diff.mark,
res.stock = diff.stock
when not matched then
insert
(res.mark,
res.stock,
res.some_unique_id)
values
(diff.mark,
diff.stock,
diff.some_unique_id);
这篇关于合并来自不同数据库的 2 个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
将每个子标记转换为具有多个分隔符的单列-SQLConverting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(将每个子标记转换为具有多个分隔符的单列-SQ
如何从多个表创建视图?How can I create a view from more than one table?(如何从多个表创建视图?)
根据前一行内的计算值创建计算值Create calculated value based on calculated value inside previous row(根据前一行内的计算值创建计算值)
如何将表格的前两列堆叠成一列,但也仅将第三How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何将表格的前两列堆
递归 t-sql 查询Recursive t-sql query(递归 t-sql 查询)
将月份名称转换为日期/月份编号(问题和答案的组Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(将月份名称转换为日期/月份编号(问题和答案的组合