我有类似的表合并两列值从另一个表
如何合并这两个表?还有其他栏目,但这些都是一样的。
我该如何填充Table1与Table2的值或合并这些表? 在表2中只有1个客户。
因此,结果表将使所有客户都具有它们的值(表1将具有Customer4,销售额为50)。
谢谢。
我有类似的表合并两列值从另一个表
如何合并这两个表?还有其他栏目,但这些都是一样的。
我该如何填充Table1与Table2的值或合并这些表? 在表2中只有1个客户。
因此,结果表将使所有客户都具有它们的值(表1将具有Customer4,销售额为50)。
谢谢。
要更新表做
update t1
set t1.sales = t2.sales
from table1 t1
join table2 t2 on t1.customername = t2.customername
,并作为选择使用
select t1.customername,
coalesce(t1.sales, t2.sales) as sales,
t1.date,
t1.variable1
from table1 t1
left join table2 t2 on t1.customername = t2.customername
codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html – Mihai 2014-11-23 18:00:05