有关数据汇总-统计-交叉表的再优化(请进讨论)
下面是对当月的数据汇总显示,不知你可有好的方法,请你再帮优化一下,谢谢!
--汇总当月(7月)的数据
select inputdate,procdno,prodname,sum(hgp) as hgp,sum(blp) as blp,sum(fp) as fp into AAA from scjd where inputdate between '2007-7-1 ' and '2007-7-31 ' group by inputdate,procdon,prodname
--分别汇总1-31号每天的数据
select inputdate,procdno,prodname,sum(case inputdate when '2007-7-1 ' then hgp esle 0 end) as A1,sum(case inputdate when '2007-7-2 ' then hgp esle 0 end) as A2,sum(case inputdate when '2007-7-3 ' then hgp else 0 end ) as A3,
sum(case inputdate when '2007-7-4 ' then hgp esle 0 end ) A4,sum(case inputdate when '2007-7-5 ' then hgp else 0 end ) as A5,sum(case inputdate when '2007-7-6 ' then hgp else 0 end ) as A6,sum(case inputdate when '2007-7-7 ' then hgp else 0 end ) as A7,sum(case inputdate when '2007-7-8 ' then hgp else 0 end ) as A8,sum(case inputdate when '2007-7-9 ' then hgp else 0 end ) as A9,sum(case inputdate when '2007-7-10 ' then hgp else 0 end ) as A10,sum(case inputdate when '2007-7-11 ' then hgp esle 0 end) as A11,sum(case inputdate when '2007-7-12 ' then hgp esle 0 end) as A12,sum(case inputdate when '2007-7-13 ' then hgp else 0 end ) as A13,sum(case inputdate when '2007-7-14 ' then hgp esle 0 end ) A14,sum(case inputdate when '2007-7-15 ' then hgp else 0 end ) as A15,sum(case inputdate when '2007-7-16 ' then hgp else 0 end ) as A16,sum(case inputdate when '2007-7-17 ' then hgp else 0 end ) as A17,sum(case inputdate when '2007-7-18 ' then hgp else 0 end ) as A18,sum(case inputdate when '2007-7-19 ' then hgp else 0 end ) as A19,sum(case inputdate when '2007-7-20 ' then hgp else 0 end ) as A20,sum(case inputdate when '2007-7-10 ' then hgp else 0 end ) as A10,sum(case inputdate when '2007-7-21 ' then hgp esle 0 end) as A21,sum(case inputdate when '2007-7-22 ' then hgp esle 0 end) as A22,sum(case inputdate when &