计算同比
select a.* , [增长率(%)] = ((a.数据 - b.数据)/b.数据)*100 from tb a left join tb b on a.日期 = dateadd(yy , 1 , b.日期)
最好的计算方式是将日期直接计算出来,比如
SELECT a.u_r_bf, a.u_y_bf,
((a.u_y_bf-b.u_y_bf)*100/b.u_y_bf) u_y_bfb
FROM hnother.tb_day a
left join hnother.tb_day b
on a.comcode =b.comcode
WHERE a.tbdate = '2010/04/25'
AND a.comcode matches '41??0000'
and b.tbdate = '2010/3/24'
ORDER BY a.comcode
这样比较省时间,效率会更加高一些