有专门工具!google上收一下!
比如:http://www.chinaitpower.com/A/2005-05-31/118223.html

解决方案 »

  1.   

    filebat :
    可以最个例子吗?
    谢谢。
      

  2.   

    --测试数据
    create table ta(月份  varchar(20), 渠道商 varchar(20),
     总票数 int, 总毛利 real, 总重量  real)
    go
    insert ta select '2005年7月','DHL',3,367.0000,37.0
    union all select '2005年7月','Feldex',1, 6677.0000,456.0
    union all select '2005年7月','OCS'   ,1, 2346.0000,3.0
    union all select '2005年8月','DHL'   ,16,7345.0000,1036.0
    union all select '2005年8月','Feldex',13,88032.0000, 52
    union all select '2005年8月','OCS'   ,3, 434.0000,135.5
    union all select '2005年8月','国内'  ,3, 317.0000,77.0
    union all select '2005年9月','DHL'   ,2, 2801.0000,378.0
    union all select '2005年9月','OCS'   ,1, 230.0000,20.0
    --主要部分
    select tt.月份, tt.渠道商,总票数=isnull(ta.总票数,0),
           总毛利=isnull(ta.总毛利,0),总重量=isnull(ta.总重量,0)
    from ta right join
    (select distinct * 
     from (select 月份 from ta) t1 , (select 渠道商 from ta)t2)tt
    on tt.月份=ta.月份 and tt.渠道商=ta.渠道商
    --清除
    drop table ta
      

  3.   

    select 
           A.[月份],
           A.[渠道商],
           [总票数]=isnull(B.[总票数],0),
           [总毛利]=isnull(B.[总毛利],0),
           [总重量]=isnull(B.[总重量],0)
    from (
           select [月份]='2005年7月',[渠道商]='DHL'
           union 
           select [月份]='2005年7月',[渠道商]='Feldex'
           union 
           select [月份]='2005年7月',[渠道商]='OCS'
           union 
           select [月份]='2005年7月',[渠道商]='国内'
           union
           select [月份]='2005年8月',[渠道商]='DHL'
           union 
           select [月份]='2005年8月',[渠道商]='Feldex'
           union 
           select [月份]='2005年8月',[渠道商]='OCS'
           union 
           select [月份]='2005年8月',[渠道商]='国内'
           union
           select [月份]='2005年9月',[渠道商]='DHL'
           union 
           select [月份]='2005年9月',[渠道商]='Feldex'
           union 
           select [月份]='2005年9月',[渠道商]='OCS'
           union 
           select [月份]='2005年9月',[渠道商]='国内'
         )A
    left join 你的视图 B on A.[月份]=B.[月份] and A.[渠道商]=B.[渠道商]