难点的解决可以如下:
select 地区,分类, sum(目标数量)  from tb1 group by 地区,分类
难道是我想的太简单了

解决方案 »

  1.   

    select 地区,物料分类, sum(目标数量)  from tb1 group by 地区,物料分类
      

  2.   

    create table ccc(deptid varchar(10),custid varchar(10),clsid varchar(10),amount money)
    insert into ccc values ('1','1','1',100)
    insert into ccc values ('1','2','1',200)
    insert into ccc values ('1','2','3',300)
    insert into ccc values ('2','1','1',100)
    insert into ccc values ('2','3','2',200)
    insert into ccc values ('2','3','3',100)
    insert into ccc values ('3','2','2',500)select *
    from (
        select deptid,custid,clsid,sum(amount) as fsum
        from ccc 
        group by deptid,custid,clsid
        with cube
          ) t1
    where deptid is not null
    order by isnull(deptid,'ZZ'),isnull(custid,'ZZ'),isnull(clsid ,'ZZ')应该就可以得到结果了,再把格式改改就行了。
      

  3.   

    若用编程工具,这类问题不难实现,如:用PB程序做为客户端,可以用DATAWINDDOWS的GROUP 实现。
      

  4.   

    用with rollup是不是更好?