不是啊 我是要这样的select count(1),sum(fee_code),fee_code from aa-bb-cc001 where substring(mtid,5,3)='999' and respond_result=0 group by fee_code这样我只能查出一张表 我要一下子查出里面所有的表的内容啊 而不是单单一张aa-bb-cc001 能用带参数的语法写出来吗??
select count(1),sum(fee_code),fee_code from aa-bb-cc001 where substring(mtid,5,3)='999' and respond_result=0 group by fee_code union all select count(1),sum(fee_code),fee_code from aa-bb-cc002 where substring(mtid,5,3)='999' and respond_result=0 group by fee_code union all select count(1),sum(fee_code),fee_code from aa-bb-cc003 where substring(mtid,5,3)='999' and respond_result=0 group by fee_code union all select count(1),sum(fee_code),fee_code from aa-bb-cc004 where substring(mtid,5,3)='999' and respond_result=0 group by fee_code union all select count(1),sum(fee_code),fee_code from aa-bb-cc005 where substring(mtid,5,3)='999' and respond_result=0 group by fee_code ... 以下一样
晕,“我在系统中有很多这样的”,我还以为是数据叻,没想到是表名。那就用Union Allselect count(1),sum(fee_code),fee_code from [aa-bb-cc001] where substring(mtid,5,3)='999' and respond_result=0 group by fee_code Union All select count(1),sum(fee_code),fee_code from [aa-bb-cc002] where substring(mtid,5,3)='999' and respond_result=0 group by fee_code Union All select count(1),sum(fee_code),fee_code from [aa-bb-cc003] where substring(mtid,5,3)='999' and respond_result=0 group by fee_code Union All select count(1),sum(fee_code),fee_code from [aa-bb-cc004] where substring(mtid,5,3)='999' and respond_result=0 group by fee_code Union All select count(1),sum(fee_code),fee_code from [aa-bb-cc005] where substring(mtid,5,3)='999' and respond_result=0 group by fee_code Union All select count(1),sum(fee_code),fee_code from [aa-bb-cc006] where substring(mtid,5,3)='999' and respond_result=0 group by fee_code Union All select count(1),sum(fee_code),fee_code from [aa-bb-cc007] where substring(mtid,5,3)='999' and respond_result=0 group by fee_code Union All select count(1),sum(fee_code),fee_code from [aa-bb-cc008] where substring(mtid,5,3)='999' and respond_result=0 group by fee_code Union All select count(1),sum(fee_code),fee_code from [aa-bb-cc009] where substring(mtid,5,3)='999' and respond_result=0 group by fee_code
你是要查询所有表中满足这个条件的记录吗?? 你看这样行不行,将表放到一个视图中,你查询直接访问视图。 Create View List As Select * from [aa-bb-cc001] Union All Select * from [aa-bb-cc001] Union All Select * from [aa-bb-cc002] Union All Select * from [aa-bb-cc003] Union All Select * from [aa-bb-cc004] Union All Select * from [aa-bb-cc005] Union All Select * from [aa-bb-cc006] Union All Select * from [aa-bb-cc007] Union All Select * from [aa-bb-cc008] Union All Select * from [aa-bb-cc009] GO Select count(1),sum(fee_code),fee_code from List where substring(mtid,5,3)='999' and respond_result=0 group by fee_code
aa-bb-cc001
where substring(mtid,5,3)='999' and respond_result=0
group by fee_code这样我只能查出一张表
我要一下子查出里面所有的表的内容啊 而不是单单一张aa-bb-cc001
能用带参数的语法写出来吗??
where substring(mtid,5,3)='999' and respond_result=0
group by fee_code
union all
select count(1),sum(fee_code),fee_code from aa-bb-cc002
where substring(mtid,5,3)='999' and respond_result=0
group by fee_code
union all
select count(1),sum(fee_code),fee_code from aa-bb-cc003
where substring(mtid,5,3)='999' and respond_result=0
group by fee_code
union all
select count(1),sum(fee_code),fee_code from aa-bb-cc004
where substring(mtid,5,3)='999' and respond_result=0
group by fee_code
union all
select count(1),sum(fee_code),fee_code from aa-bb-cc005
where substring(mtid,5,3)='999' and respond_result=0
group by fee_code
...
以下一样
[aa-bb-cc001]
where substring(mtid,5,3)='999' and respond_result=0
group by fee_code
Union All
select count(1),sum(fee_code),fee_code from
[aa-bb-cc002]
where substring(mtid,5,3)='999' and respond_result=0
group by fee_code
Union All
select count(1),sum(fee_code),fee_code from
[aa-bb-cc003]
where substring(mtid,5,3)='999' and respond_result=0
group by fee_code
Union All
select count(1),sum(fee_code),fee_code from
[aa-bb-cc004]
where substring(mtid,5,3)='999' and respond_result=0
group by fee_code
Union All
select count(1),sum(fee_code),fee_code from
[aa-bb-cc005]
where substring(mtid,5,3)='999' and respond_result=0
group by fee_code
Union All
select count(1),sum(fee_code),fee_code from
[aa-bb-cc006]
where substring(mtid,5,3)='999' and respond_result=0
group by fee_code
Union All
select count(1),sum(fee_code),fee_code from
[aa-bb-cc007]
where substring(mtid,5,3)='999' and respond_result=0
group by fee_code
Union All
select count(1),sum(fee_code),fee_code from
[aa-bb-cc008]
where substring(mtid,5,3)='999' and respond_result=0
group by fee_code
Union All
select count(1),sum(fee_code),fee_code from
[aa-bb-cc009]
where substring(mtid,5,3)='999' and respond_result=0
group by fee_code
你看这样行不行,将表放到一个视图中,你查询直接访问视图。
Create View List
As
Select * from [aa-bb-cc001]
Union All
Select * from [aa-bb-cc001]
Union All
Select * from [aa-bb-cc002]
Union All
Select * from [aa-bb-cc003]
Union All
Select * from [aa-bb-cc004]
Union All
Select * from [aa-bb-cc005]
Union All
Select * from [aa-bb-cc006]
Union All
Select * from [aa-bb-cc007]
Union All
Select * from [aa-bb-cc008]
Union All
Select * from [aa-bb-cc009]
GO
Select count(1),sum(fee_code),fee_code from List
where substring(mtid,5,3)='999' and respond_result=0
group by fee_code