SELECT 产品名称,部门名称,sum(数量) from table group by 产品名称,部门名称在编程将数据重新排列即可

解决方案 »

  1.   

    再编程?再用sql语言编程可以么?怎样实现?谢谢。
      

  2.   

    我认为不需要用sql,用开发语言自己加工就成了
      

  3.   

    其实有其他的方案可以达到你所要求的效果。完全SQL。
    只不过排列方式而已。
    若非要如此只能用临时表解决了。过程并不不简单哪。
      

  4.   

    部门有限而且知道:
    sql server:select 产品名称,
       sum(数量) as 合计,
       sum(case when 部门名称='部门1' then 数量 else 0 end) as 部门1,
       sum(case when 部门名称='部门2' then 数量 else 0 end) as 部门2,
    ...
       sum(case when 部门名称='部门N' then 数量 else 0 end) as 部门N
    group by 产品名称
    union all
    select '合计' as 产品名称,
       sum(数量) as 合计,
       sum(case when 部门名称='部门1' then 数量 else 0 end) as 部门1,
       sum(case when 部门名称='部门2' then 数量 else 0 end) as 部门2,
    ...
       sum(case when 部门名称='部门N' then 数量 else 0 end) as 部门N如果是其他数据库或者部门不知道请说明。
      

  5.   

    我用的是access数据库,应该差不错一样吧。
      

  6.   

    在VFP中用交叉表查询做:语句为:
    SELECT A.产品名, A.部门名, SUM(A.数量);
        FROM '原始表.DBF' A;
        GROUP BY A.产品名, A.部门名;
        ORDER BY A.产品名, A.部门名;
        INTO CURSOR SYS(2015)
    DO (_GENXTAB) WITH 'Query',.t.,.t.,.t.,,,,.t.,0,.f.
    BROWSE NOMODIFY
      

  7.   

    Sum(Case When 部门名称='部门1' then 数量 end)'部门1'
    含这个语句执行的时候出现错误信息:‘不支持此接口’。
    我用的是access数据库,该怎样解决?