2010-08-06 71 views
0

首先我使用的readline 5.0MySQL的十進制查詢問題

很抱歉的格式運行MySQL版本14.12 5.0.45 DISTRIB,對紅帽Linux的GNU的(x86_64的),但我沒有複製能力它,所以我必須將它的類型。

所討論的兩個字段

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錯誤或我誤解了某種概念。先謝謝您的幫助。

回答

0

十進制(38,6)將是一個浮點類型,具有與該類型相關的所有困難。在這種情況下,這意味着顯示的一些值不是確切的值。該列的大小使我直到你懷疑的基本型已經是雙精度,所以詢問此列,你需要做這樣的事情......

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

和小提琴與delta值所需的結果,或重新設計列,以便您可以使用INTEGER或CHAR類型。