选择右列 [英] Selecting the right column

查看:80
本文介绍了选择右列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询.

with result as
(
select t1.name, t1.number, t2.number from table1 t1, table2 t2 where some conditions
union all
select t1.name, t1.number, t3.number from table1 t1, table3 t3 where some conditions
)select * from result

我需要在表5中插入t1.name和t2.number

I need to insert in table5 t1.name and t2.number

table5与t1的列相同.

table5 has the same columns as t1.

如果我做类似

insert in table5(name, number)
select r.name, r.number from result r

什么是r.number? t1.number或t2.number?因为列具有相同的名称.还是有办法区分?我怎样才能使查询跳过带有t3.number的每一行?我什至可以做到吗?

what would be considered r.number? t1.number or t2.number? Because columns have the same name. Or is there a way to defferentiate? How can I make it so the query skips every row with t3.number? Can I even do it?

例如,我有table1

For example I have table1

A (+1)11111111
B (+1)22222222
C (+1)33333333

table2

(+2)44444444
(+2)55555555

首先选择会得到我

A (+1)11111111 (+2)44444444
B (+1)22222222 (+2)55555555

table3

(+3)66666666
(+3)88888888
(+3)97898789

第二选择的结果

B (+1)22222222 (+3)88888888
C (+1)33333333 (+3)97898789

这将是全部并集的结果

A (+1)11111111 (+2)44444444
B (+1)22222222 (+2)55555555
B (+1)22222222 (+3)88888888
C (+1)33333333 (+3)97898789

我到底想要什么

A (+2)44444444
B (+2)55555555

最终结果不应包含该行

B (+1)22222222 (+3)88888888
C (+1)33333333 (+3)97898789

推荐答案

两者.在某些行中,t2.numbernumber,在另一些行中,t3.numbernumber.

Both. In some rows, t2.number is number and in others t3.number is number.

union all的结果在单个结果集中.结果集不知道任何特定列中值的来源(尽管您可以在此列中包含此信息).

The result of the union all in a single result set. The result set doesn't know the origin of the values in any particular column (although you could include another column with this information).

这篇关于选择右列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆