如何将sql查询舍入到较低的整数

时间:2017-05-19 12:33:21

标签: mysql sql select floating-point rounding

例如我有一个查询:

select (select size from acc where acc_id = 1)/(select count(m_id) from m_acc  JOIN dns ON dns.dns_id = m_acc.dns_id where acc_id = 1)*1000000;

查询结果:

3333333333.3330

我想要

3333333333

我不需要舍入到大写整数。我想要舍入到更低的整数。我试过这样做:

select floor (select size from acc where acc_id = 1)/(select count(m_id) from m_acc  JOIN dns ON dns.dns_id = m_acc.dns_id where acc_id = 1)*1000000;

但结果我得到了这个:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'size from acc where acc_id = 1)/(select coun' at line 1

请告诉我,我有错误?

1 个答案:

答案 0 :(得分:1)

使用FLOOR()。试试这个:

select FLOOR
(
    (select size from acc where acc_id = 1)
    /
    (select count(m_id) from m_acc  JOIN dns ON dns.dns_id = m_acc.dns_id where acc_id = 1)
    *
    1000000
);