日期:2014-05-18 浏览次数:20776 次
select x_id=isnull(x_id,'总和'),x_sale=sum(x_sale) from [table1] where x_date between '2009-12-01' and '2009-12-03' group by x_id with rollup
------解决方案--------------------
--> 测试数据: [table1] if object_id('[table1]') is not null drop table [table1] create table [table1] (x_ID varchar(10),x_sale int,x_date datetime) insert into [table1] select 'A',200,'2009-12-01' union all select 'B',300,'2009-12-01' union all select 'A',100,'2009-12-02' union all select 'C',70,'2009-12-02' union all select 'B',50,'2009-12-03' union all select 'A',150,'2009-12-03' select x_id=isnull(x_id,'总和'),x_sale=sum(x_sale) from [table1] where x_date between '2009-12-01' and '2009-12-03' group by x_id with rollup --结果: x_id x_sale ---------- ----------- A 450 B 350 C 70 总和 870
------解决方案--------------------
Select TABLE1.x_ID,SUM(TABLE1.x_sale) AS sumsalein FROM WHERE (TABLE1.x_date BETWEEN '"&2009-12-01
&"' AND '"&2009-12-03&"') GROUP BY TABLE1.x_ID
union all
Select '总和',SUM(TABLE1.x_sale) AS sumsalein FROM WHERE (TABLE1.x_date BETWEEN '"&2009-12-01
&"' AND '"&2009-12-03&"')
===============
加个union all 就行了