--创建表:
create table invertery (item char(10),color varchar(10),quantity int)
insert invertery
select 'Chair','Blue',50 union all
select 'Chair','Red',100 union all
select 'Table','Blue',24 union all
select 'Table','Red',123 union all
select 'Chair','Blue',51 union all
select 'Chair','Red',110 union all
select 'Table','Blue',100 union all
select 'Table','Red',100
--对数据进行分类求和及求其总和查询:
select item,color,sum(quantity) as qtysum
from invertery
group by item,color
with rollup
查询结果为:
item color qtysum
------------ --------------- ---------------
Chair Blue 101
Chair Red 210
Chair NULL 311
Table Blue 124
Table Red 223
Table NULL 347
NULL NULL 658
现在想得到以下的查询结果(多了红色的字), 查询语句该如何写?
查询结果为:
item color qtysum
------------ --------------- ---------------
Chair Blue 101
Chair Red 210
Chair 汇总 NULL 311
Table Blue 124
Table Red 223
Table 汇部 NULL 347
总计 NULL 658