0

我有一个问题,如何将百分比相加为 100.00。我尝试使用“圆形”,但结果只显示 99.93。有人知道吗?

SELECT Sum(percent) 
FROM   (SELECT state, 
               jantina, 
               bilmale, 
               jds, 
               jumall, 
               Round(( bilmale * 100 / ( jumall ) ), 2) PERCENT, 
               ( jds ) * 100 / ( jumall )               AS p_jdk 
        FROM   (SELECT Timestamp(X.createdate) 
                             dattime 
                       , 
                       Upper(Date_format(X.createdate, '%d %M %Y'))      AS 
                       datenegeri, 
                       X.state, 
                       Upper(CASE 
                               WHEN g.ns_fender_desc = 'male' THEN 'LELAKI' 
                               WHEN g.ns_fender_desc = 'female' THEN 'PEREMPUAN' 
                               ELSE g.ns_fender_desc 
                             END)                                        jantina 
                       , 
                       Sum(CASE 
                             WHEN X.male = 1 THEN 1 
                             WHEN X.male = 0 THEN 1 
                             ELSE 0 
                           END)                                          bilmale 
                       , 
                       (SELECT Sum(CASE 
                                     WHEN Y.male = 1 THEN 1 
                                     WHEN Y.male = 0 THEN 1 
                                     ELSE 0 
                                   END) bilmale 
                        FROM   xyuser_userext Y 
                               JOIN tnsstate TS 
                                 ON TS.ns_state_id = Y.state 
                               LEFT JOIN tnsgender g 
                                      ON g.ns_gender_id = Y.male 
                        WHERE  Y.statususerext IN ( '0', '1', '2', '5' ) 
                               AND Y.state = X.state 
                               AND Date_format(X.createdate, '%d %M %Y') = 
                                   Date_format(Y.createdate, '%d %M %Y') 
                        GROUP  BY TS.ns_state_desc, 
                                  Date_format(X.createdate, '%d %M %Y')) jds, 
                       (SELECT Sum(CASE 
                                     WHEN Y.male = 1 THEN 1 
                                     WHEN Y.male = 0 THEN 1 
                                     ELSE 0 
                                   END) bilmale 
                        FROM   xyuser_userext Y 
                               JOIN tnsstate TS 
                                 ON TS.ns_state_id = Y.state 
                               LEFT JOIN tnsgender g 
                                      ON g.ns_gender_id = Y.male 
                        WHERE  Y.statususerext IN ( '0', '1', '2', '5' ))jumall 
                FROM   xyuser_userext X 
                       JOIN tnsstate TS 
                         ON TS.ns_state_id = X.state 
                       LEFT JOIN tnsgender g 
                              ON g.ns_gender_id = X.male 
                WHERE  X.statususerext IN ( '0', '1', '2', '5' ) 
                GROUP  BY TS.ns_state_desc, 
                          Date_format(X.createdate, '%d %M %Y'), 
                          X.male 
                ORDER  BY 1 ASC) AS A) AS b
4

1 回答 1

0

如果只对结果而不是单个项目进行四舍五入,它会更准确。尝试SELECT Round(Sum(percent), 2)在 WHERE 子句的百分比计算中使用并删除 Round。

于 2013-01-23T02:39:03.767 回答