sql server :
如果品名有限可知:
select 地点,
Nullif(sum(case when 品名='A' then 销量 else 0 end),0) as A,
Nullif(sum(case when 品名='B' then 销量 else 0 end),0) as B,
Nullif(sum(case when 品名='C' then 销量 else 0 end),0) as C,
Nullif(sum(case when 品名='D' then 销量 else 0 end),0) as D
from tablename
grou by 地点

解决方案 »

  1.   

    谢谢 Yang_(扬帆破浪) 各位还有什么高见!
      

  2.   

    transform sum([销量]) select [地点] from 表格 group by [地点] order by [地点] pivot [品名]这是基本的交叉表查询呀!来点难得。
      

  3.   

    to  w_rose(w_rose) 
    没学过,谢谢!
      

  4.   

    to w_rose(w_rose) 
    请问这是标准的SQL语句么,我要在SYBASE中使用
      

  5.   

    不是标准语句,适用MS SQL SERVER,SYBASE应该也可以。
      

  6.   

    w_rose(w_rose)说的是ACCESS的语句,SYBASE应该不可以
      

  7.   

    sybase中怎样写,有人知道吗?
      

  8.   

    试一试在SYBASE一下语句可不可以:select 地点,
    sum(case when 品名='A' then 销量 else 0 end) as A,
    sum(case when 品名='B' then 销量 else 0 end) as B,
    sum(case when 品名='C' then 销量 else 0 end) as C,
    sum(case when 品名='D' then 销量 else 0 end) as D
    from tablename
    grou by 地点不过结果有点不一样:       品名
     地点   |    A       B      C       D
    ------------------------------------——
      甲    |   100     200    300      0
      乙    |   0        50    0        80
      丙    |   200     400    0        0
      

  9.   

    select distinct 地点,
    (select sum(销量) from tablename where 品名='A') as A,
    (select sum(销量) from tablename where 品名='B') as B,
    (select sum(销量) from tablename where 品名='C') as C,
    (select sum(销量) from tablename where 品名='D') as D
    from tablename
      

  10.   

    to Yang_(扬帆破浪) 
    原来SYBASE可以按case的方法做,我开始试的时候写错了,深表感谢!顺便说一下,最后的一个方法没用,结果每一行全是一样的。