2 回答
TA贡献1886条经验 获得超2个赞
如果两个表的结构是相同的,可以建个临时表
==================================
补充:
表t_test1(id, age )
表中数据 1, 1
2, 2
3, 3
4, 4
表t_test2(id, age )
表中数据 1, 6
2, 7
3, 8
如想把俩表合并可以如下:
--------sql---start-------------------
create table tempTest (
tid int primary key IDENTITY (1, 1) NOT NULL,
id int ,
age int ,
tbl int
)
insert into tempTest(id,age,tbl) select *,1 from t_test1
insert into tempTest(id,age,tbl) select *,2 from t_test2
select * from tempTest
drop table tempTest
--------sql-----end-----------------
select * from tempTest查询的结果是
tid id age tbl(表的标识)
1 1 1 1
2 2 2 1
3 3 3 1
4 4 4 1
5 1 6 2
6 2 7 2
7 3 8 2
==============================================
如果你能保证两个表的主键id不重复,即
表t_test2(id, age )
表中数据改为 6, 6
7, 7
8, 8
则可以如下简化:
--------sql---start-------------------
create table test (
id int NOT NULL ,
age int ,
)
insert into test(id,age) select * from t_test1
insert into test(id,age) select * from t_test2
select * from test
drop table test
--------sql-----end-----------------
select * from test查询的结果是
id age
1 1
2 2
3 3
4 4
6 6
7 7
8 8
TA贡献1874条经验 获得超12个赞
我看到你只是要从两张表里求有符合条件的多少条, 再求和, 所以就这样写了.
select ((select count(*) from clientdefine where extra2='1')+(select count(*) from channel where extra2='1')) from dual
- 2 回答
- 0 关注
- 570 浏览
添加回答
举报
