select max(b.areaName) as 地区,
(select count(*) from xls where areaParentCode=a.areaParentCode and [年] = '2006年' and rtrim(ltrim(专利类型))='发明') as '2006年' ,
(select count(*) from xls where areaParentCode=a.areaParentCode and [年] = '2007年' and rtrim(ltrim(专利类型))='发明') as '2007年' 
 from xls a,dic_postalCode b where a.areaParentCode=b.postalID and b.postalparentID='0' group by a.areaParentCode这是查询语句,需要在第3列 输出2年数据的增幅 ,第4列输出2年的差值
请问怎么办
------------------------
例子如             (数1-数2)
数1    数2  增长率   增幅
210    113   85.8    97
183    127   44.1    56急~~~~~~~~~~~~~~~~~~~~~~~~~~~~

解决方案 »

  1.   

    select *, ([2007年] - [2006年]) * 1.0 / [2006年] As 增长率, [2007年] - [2006年] As 增幅
    from
    (
    select max(b.areaName) as 地区,
    (select count(*) from xls where areaParentCode=a.areaParentCode and [年] = '2006年' and rtrim(ltrim(专利类型))='发明') as '2006年' ,
    (select count(*) from xls where areaParentCode=a.areaParentCode and [年] = '2007年' and rtrim(ltrim(专利类型))='发明') as '2007年' 
     from xls a,dic_postalCode b where a.areaParentCode=b.postalID and b.postalparentID='0' group by a.areaParentCode
    ) A