2个回答
展开全部
结果1:
select T3.addr,T3.ip,sum(num) as num from (select * from T1 union all select * from T2) T3 group by T3.addr,T3.ip
结果2:
select v1.addr,v1.ip,T1.num as num1,T2.num as num2 from (select T3.addr,T3.ip from (select * from T1 union all
select * from T2) T3 group by T3.addr,T3.ip) v1 left join T1 on v1.addr=T1.addr
left join T2 on v1.addr=T2.addr
效果:
追问
我调试了,成功了!!O(∩_∩)O谢谢,在问个问题:union all是不是只能用于两个表??假入我有10、20个表,还能用union all么???
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select addr,ip,sum(num)
from (
select a.* from a
union all
select b.* from b
)
group by addr,ip
select a.addr,a.ip a,num num1 b.num num2
from a
full join b
on a.addr=b.addr
from (
select a.* from a
union all
select b.* from b
)
group by addr,ip
select a.addr,a.ip a,num num1 b.num num2
from a
full join b
on a.addr=b.addr
追问
后面那段是得出结果2的语句把?我没调试,看了一下,你这样只列出了表1中有的字段,没有查出表2中有而表1中没有的字段??你查出的语句中应该只有addr1、3、5、7没有addr4、6!!???
追答
我用的是full join 就是把所有的都结合
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询