select a.编码,a.日,a.日销量,b.月销量,c.年销量
from(select 编码,日,月,年,日销量=sum(销售数) from 表 group by 编码,日,月,年)a,
    (select 编码,月,年,月销量=sum(销售数) from 表 group by 编码,月,年)b,
    (select 编码,年,年销量=sum(销售数) from 表 group by 编码,年)c
where a.编码=b.编码 and a.月=b.月 and a.年=b.年
    and a.编码=c.编码 and a.年=c.年

解决方案 »

  1.   

    你所要的日是不是上一个表的“年+月+日”?
    如果是的话,可以这样
    select 编码,年+月+日 as 日,
    日销量=(select sum(销售数) from table group by 编码,日,月,年),
    月销量=(select sum(销售数) from table group by 编码,月,年),
    年销量=(select sum(销售数) from table group by 编码,年)
    from table order by 编码
      

  2.   

    select a.编码,a.日,a.日销量,b.月销量,c.年销量
    from(select 编码,日,月,年,日销量=sum(销售数) from 表 group by 编码,日,月,年)a,
        (select 编码,月,年,月销量=sum(销售数) from 表 group by 编码,月,年)b,
        (select 编码,年,年销量=sum(销售数) from 表 group by 编码,年)c
    where a.编码=b.编码 and a.月=b.月 and a.年=b.年
        and a.编码=c.编码 and a.年=c.年
      

  3.   

    select a.编码,a.日+a.月+a.年,a.日销量,b.月销量,c.年销量
    from(select 编码,日,月,年,日销量=sum(销售数) from 表 group by 编码,日,月,年)a,
        (select 编码,月,年,月销量=sum(销售数) from 表 group by 编码,月,年)b,
        (select 编码,年,年销量=sum(销售数) from 表 group by 编码,年)c
    where a.编码=b.编码 and a.月=b.月 and a.年=b.年
        and a.编码=c.编码 and a.年=c.年