不明白!select storename as 仓库名 from table

解决方案 »

  1.   

    是这样的,例如我查询商品列表出来,含有名称,单位,数量,仓库名称等,列表标题应是:名称,单位,数量,仓库名,
            商品名1 个   10    本部
            商品名1 个   10    门市
            商品名2 对   20     本部
            商品名2 对   20     门市
    要变成标题:名称,单位,本部,门市,总库存
              商品名1 个   10    10    20
              商品名2 对   20    20    40
    sql2000的sql怎么写?
      

  2.   

    select Name as 名称
    ,Unit as 单位
    ,本部=(select sum(counts) from tablename where Name=a.Name and Dept1='门市') 
    ,本部=(select sum(counts) from tablename where Name=a.Name and Dept1='门市')
    ,总库存=(select sum(counts) from tablename where Name=a.Name)
    from tablename a
    group by Name
      

  3.   

    select 字段名 as 仓库,字段名 as xxx from table
      

  4.   

    没办法,交叉制表select 名称,单位,sum(case when 仓库名称 ='本部' then 数量 else 0 end) as 本部
    ,sum(case when 仓库名称 ='门市' then 数量 else 0 end) as 门市
    ,sum(数量) as 总库存
    from table1 
    group by 名称,单位
      

  5.   

    在acess2002可用TRANSFORM 统计字段 和PIVOT 要变成标题的字段很快就可以变换位置,而且仓库名称也是动态变化的,如用以上两种方法可能较为繁难有没有想acess的快捷方法,我想在sql2000里应该也有。请教各位。
      

  6.   

    newly_ignorant(不学无术) 的方式不错,如查不嫌麻烦的话,
    还可以这样写:SELECT 名称,单位,sum(本部) AS 本部,sum(门市) AS 门市,sum(总库存) As 总库存
      FROM (SELECT 名称,单位,
            (case when 仓库名称 ='本部' then ISNULL(数量,0) else 0 end) as 本部,
            (case when 仓库名称 ='门市' then ISNULL(数量,0) else 0 end) as 门市,,数量 as 总库存
        from table1 ) AS D_View
      WHERE 1=1
      group by 名称,单位
      

  7.   

    不法理解!select storename as 仓库名 from table