0

我正在尝试计算 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  
4

1 回答 1

1

尝试 1.00*(my1.YTDTY - ly1.YTDLY) / ly1.YTDLY。如果您的列类型是整数,则除法不会得到非整数结果,除非您强制分子为小数或浮点数。

于 2012-07-04T21:41:03.293 回答