我正在努力计算2年之间增长的百分比,但它将增长率恢复为0。
SELECT my.finmonth,
my.trnyear,
my.drawofficenum,
my1.ytdty,
ly1.ytdly,
CASE
WHEN my1.ytdty <> 0 THEN ( my1.ytdty - ly1.ytdly ) / ly1.ytdly * 100
ELSE 0
END AS Growth2012
FROM salestymonth my
LEFT JOIN salestyytd my1
ON my.finmonth = my1.finmonth
AND my.trnyear = my1.trnyear
AND my.drawofficenum = my1.drawofficenum
LEFT JOIN saleslyytd ly1
ON my.finmonth = ly1.finmonth
AND my.trnyear = ly1.trnyear
AND my.drawofficenum = ly1.drawofficenum
WHERE my.finmonth = '1'
ORDER BY ytdty DESC
答案 0 :(得分:1)
尝试1.00 *(my1.YTDTY - ly1.YTDLY)/ ly1.YTDLY。如果您的列类型是整数,除非您强制分子为小数或浮点数,否则不会从除法中得到非整数结果。