Try:
Select * from 表A
Union all
Select 5,'b_all',sum(field2),sum(field3) from 表A where field1 = 'b'
group by 5,'b_all'
Union all
Select 6,'b_all',sum(field2),sum(field3) from 表A where field1 = 'c'
group by 5,'b_all'
Select * from 表A
Union all
Select 5,'b_all',sum(field2),sum(field3) from 表A where field1 = 'b'
group by 5,'b_all'
Union all
Select 6,'b_all',sum(field2),sum(field3) from 表A where field1 = 'c'
group by 5,'b_all'
union all
select 5,'b_all',sum(field2),sum(field3) from a where field1='b'
union all
select 6,'c_all',sum(field2),sum(field3) from a where field1='c'
Select * from 表A
Union all
Select 5 ,'b_all' ,sum(field2),sum(field3) from test where field1 = 'b'
Union all
Select 6,'c_all',sum(field2),sum(field3) from 表A where field1 = 'c'
Union all
Select (select max(id) from 表A)+1 ,'b_all' ,sum(field2),sum(field3) from 表A where field1 = 'b'
Union all
Select (select max(id) from 表A)+2,'c_all',sum(field2),sum(field3) from 表A where field1 = 'c'
((select Field1,Field2,Field3 from 表A Union all
select Field1+'_all',sum(Field2),sum(Field3)
from 表A group by Field1)) Tselect * from #tempdrop table #temp
Union all
Select (select max(id) from 表A)+1 ,'b_all' ,sum(field2),sum(field3) from 表A where field1 = 'b'
Union all
Select (select max(id) from 表A)+2,'c_all',sum(field2),sum(field3) from 表A where field1 = 'c' order by id
create table 表A (id int,field1 char(1),field2 numeric(10,1),field3 numeric(10,1))
insert 表A select 1 ,'b', 10.1, 12.2
union all select 2 ,'b', 9.8, 8.6
union all select 3 ,'c', 12.3, 11.2
union all select 4 ,'c', 5.3, 8.2Select * from 表A
Union all
Select (select max(id) from 表A)+1 ,'b_all' ,sum(field2),sum(field3) from 表A where field1 = 'b'
Union all
Select (select max(id) from 表A)+2,'c_all',sum(field2),sum(field3) from 表A where field1 = 'c'id field1 field2 field3
----------- ------ ---------------------------------------- ----------------------------------------
1 b 10.1 12.2
2 b 9.8 8.6
3 c 12.3 11.2
4 c 5.3 8.2
5 b_all 19.9 20.8
6 c_all 17.6 19.4(所影响的行数为 6 行)