The MySQL query results show the simple implementation as a percentage

  • 2020-05-30 21:12:37
  • OfStack

I found some data, and then I used two functions from MySQL string manipulation, concat() and left()

1, CONCAT (str1 str2,...).
Returns a string from the parameter link. If any parameter is NULL, return NULL. You can have more than two arguments. One numeric parameter is converted to its string equivalent.

The sample
 
select CONCAT('My', 'S', 'QL'); 
-> 'MySQL' 

select CONCAT('My', NULL, 'QL'); 
-> NULL 

select CONCAT(14.3); 
-> '14.3' 

2, LEFT (str, length)
Intercept the string from the left. Note: left(truncated field, truncated length)

Combine 1, 2: concat (left (value 1 / value 2 *100,5),'%') as complaint rate

Related articles: