Several methods to find percentage in MYSQL

One, function introduction

1、ROUND(X,D)和ROUND(X)

The round function is used to round the data, x refers to the number to be processed, and d refers to a few decimal places

round(x) is actually round(x,0)

d can be a negative number, which means that the d-digit integer to the left of the specified decimal point is 0, and the decimal place is 0

2、FORMAT(X,D)

Provide data content formatting function, can format the data as integer or floating point number, can be rounded

When D is negative, press 0 to process

3、LEFT(str,len)

leftThe function is a string function, it returns the left part of the string with the specified length, str is the string to be processed, and len is the length

The left function is a string interception, can not be rounded

4、CONCAT(str1,str2,...)

The concat function is used to concatenate multiple strings into one string

Two, use round, format, left and concat to find the percentage

Note: When using left to intercept percentage by bit, the number of digits should be set reasonably according to the needs, otherwise it is prone to unexpected BUG

Guess you like

Origin blog.csdn.net/kk_gods/article/details/109643568