I get a player's rating from the database by the following query, where S is murder, D is death

 SELECT 'player_name', IF(D = 0, S, (S / D)) AS 'rating' FROM accounts ORDER BY IF(D = 0, S, (S / D)) DESC LIMIT 5 

How to round down? For example, S = 23, D = 4. Partial = 5.75. Need to withdraw 5.7

    1 answer 1

    As a rule, any DBMS provides the FLOOR() function, which rounds the number "down"

     SELECT 'player_name', FLOOR(IF(D = 0, S, (S / D)) * 10) / 10 AS 'rating' FROM accounts ORDER BY IF(D = 0, S, (S / D)) DESC LIMIT 5 

    Not all implementations support fractional rounding. In order to round up to the first decimal place, one usually resorts to this technique: pre-multiply the number by 10, and after applying the FLOOR() function, divide by 10.