如何在以下查询中将“百分比”四舍五入到小数点后两位?

时间:2013-12-12 14:37:10

标签: mysql sql

我的查询如下:

SELECT *, 
       MATCH (question_text) AGAINST 
             ('A nucleotide consists of' IN NATURAL LANGUAGE MODE) AS percentage 
FROM OCN.match_questions 
WHERE MATCH (question_text) AGAINST 
            ('A nucleotide consists of' IN NATURAL LANGUAGE MODE)

我希望在整数之后将百分比减去两位小数,或者只取整数部分。我需要的两个查询但我无法以正确的方式编写它。我尝试了以下查询,但没有成功。

SELECT *, 
       MATCH (question_text) AGAINST 
             ('A nucleotide consists of' IN NATURAL LANGUAGE MODE) 
             AS ROUND(percentage,2) 
FROM OCN.match_questions 
WHERE MATCH (question_text) AGAINST 
      ('A nucleotide consists of' IN NATURAL LANGUAGE MODE)

1 个答案:

答案 0 :(得分:1)

试试这个:

SELECT *, 
       ROUND( 
          -- a first parameter of ROUND goes here:
          MATCH (question_text) AGAINST 
                    ('A nucleotide consists of' IN NATURAL LANGUAGE MODE) 
          -- and a second parameter of ROUND goes after the comma:
             , 2 ) AS percentage
FROM ........

http://dev.mysql.com/doc/refman/5.1/en/mathematical-functions.html#function_round

  

ROUND(X,D)
  将参数X舍入到D小数位。

  X是第一个参数,D是第二个参数