如何获得带小数位数的mysql结果到2

时间:2016-01-25 05:03:08

标签: mysql sql

我有以下查询..

SELECT p.product_id,p.description,sum(sl.qty*sl.factor) as qty
FROM sale_line as sl
LEFT JOIN sale as s ON(sl.sale_id=s.sale_id)
LEFT JOIN product as p ON(p.product_id=sl.product_id)
ORDER BY sl.product_id DESC;

我想得到"总和(sl.qty * sl.factor)为数量"字段舍入到小数点后两位。 例如。如果结果得到了13.170000484884',我想进入' 13.17'结果。

1 个答案:

答案 0 :(得分:0)

使用ROUND()功能:

ROUND(sum(sl.qty*sl.factor),2) as qty

查询:

SELECT p.product_id,p.description,ROUND(sum(sl.qty*sl.factor),2) as qty
FROM sale_line as sl
LEFT JOIN sale as s ON(sl.sale_id=s.sale_id)
LEFT JOIN product as p ON(p.product_id=sl.product_id)
ORDER BY sl.product_id DESC;