seaswalker / posts

0 stars 0 forks source link

MySQL case when生成新的列 #18

Open seaswalker opened 3 years ago

seaswalker commented 3 years ago
SELECT
    (
        case
            when c = 1 then '100%'
            ELSE concat(ROUND((a / b) * 100, 2), '%')
        end
    ) AS '百分比'
FROM
    some_table

如果c不等于1那么得到的是保留两位小数的百分比.