【问题标题】:mysql decimal query issuemysql十进制查询问题
【发布时间】:2010-08-06 11:55:35
【问题描述】:

首先,我使用 readline 5.0 为 redhat-linux-gnu (x86_64) 运行 mysql Ver 14.12 Distrib 5.0.45

对不起,我无法复制它,所以我必须输入它。

有问题的两个字段如下

id int(11)
startj1950 decimal(38,6)



mysql> select id,startj1950 from store where id = 32513;

+------------------+
| id       | startj1950           |
+----------|----------------------|
|32513     | 1912181654.500000    |
-----------------------------------

mysql> select id from store where startj1950=1912181654.500000;
Empty set

所以我认为我在副本中搞砸了,所以我会让 mysql 为我获取价值。

mysql> select id from store where startj1950=(select startj1950 from store where id=32513);
Empty set <br/>

但它适用于其他结果

mysql> select id,startj1950 from store where id = 32513;

+------------------+
| id       | startj1950           |
+----------|----------------------|
|18675     | 1907365784.570000    |
-----------------------------------

mysql> select id from store where startj1950=1907365784.570000;

+----------+
| id       |
+----------|
|18675     |
------------

mysql> select id from store where startj1950=(select startj1950 from store where  id=18675);<br/>

+----------+
| id       |
+----------|
|18675     |
------------

我想我要么遇到了 mysql 错误,要么我误解了某种概念。提前感谢您的帮助。

【问题讨论】:

    标签: mysql


    【解决方案1】:

    decimal (38, 6) 将是浮点类型,具有与该类型相关的所有困难。在这种特殊情况下,这意味着显示的某些值不是精确值。该列的大小使我怀疑基础类型已经是双精度的,因此要查询此列,您需要执行类似...

    SELECT *
        FROM store
        WHERE startj1950 BETWEEN somevalue - @delta AND somevalue + @delta;
    

    并调整 delta 的值直到获得所需的结果,或者重新设计列以便可以使用 INTEGER 或 CHAR 类型。

    【讨论】:

      猜你喜欢
      • 2022-06-21
      • 2011-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多