線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:976
推到 Plurk!
推到 Facebook!

請問SQL的問題

缺席
irvinehing
初階會員


發表:77
回覆:79
積分:31
註冊:2003-11-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-06-02 16:33:39 IP:210.186.xxx.xxx 未訂閱
環境: Win2000 SP4 BCB6 Update4 Zeos 6.5.1 問題: mysql> show columns from tb_dsales_record; --------- -------------------------- ------ ----- ---------- ------- | Field | Type | Null | Key | Default | Extra | --------- -------------------------- ------ ----- ---------- ------- | no | int(8) unsigned zerofill | YES | | 00000000 | | | product | varchar(20) | YES | | NULL | | | qty | int(11) | YES | | 1 | | | uprice | float(4,2) | YES | | 0.00 | | | amount | float(4,2) | YES | | 0.00 | | | joined | int(11) | YES | | 1 | | | odate | date | YES | | NULL | | --------- -------------------------- ------ ----- ---------- ------- 7 rows in set (0.00 sec) mysql> select * from tb_dsales_record; ---------- --------- ------ -------- -------- -------- ------------ | no | product | qty | uprice | amount | joined | odate | ---------- --------- ------ -------- -------- -------- ------------ | 00000003 | 10KG | 3 | 0.80 | 2.40 | 1 | 2005-06-02 | | 00000003 | 10KG | 3 | 0.80 | 1.20 | 2 | 2005-06-02 | | 00000003 | 10KG | 3 | 0.80 | 2.40 | 1 | 2005-06-02 | | 00000003 | 10KG | 32 | 0.80 | 25.60 | 1 | 2005-06-02 | | 00000003 | 10KG | 3 | 0.80 | 1.20 | 2 | 2005-06-02 | ---------- --------- ------ -------- -------- -------- ------------ 5 rows in set (0.01 sec) mysql> select * from tb_dsales_record where uprice=0.80; Empty set (0.00 sec) mysql> select * from tb_dsales_record where uprice='0.80'; Empty set (0.00 sec) 請問要怎樣才可以查詢出uprice=0.80的資料?
RedSnow
版主


發表:79
回覆:1322
積分:845
註冊:2003-12-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-06-03 03:07:46 IP:218.19.xxx.xxx 未訂閱
irvinehing 您好:    這是 MySQL 的 Bug,在 MySQL 的文件中有這麼一段說明: If you are comparing FLOAT or DOUBLE columns with numbers that have decimals, you can't use equality (=) comparisons. This problem is common in most computer languages because not all floating-point values can be stored with exact precision. In some cases, changing the FLOAT to a DOUBLE fixes this. See Section A.5.8, “Problems with Floating-Point Comparisons”. 由這一段說明可以知道 float 型態的資料不可以用 = 來比對,在某些狀況下,改用 double 型態可以獲得解決,您可以先試試看,若仍不行的話,就查看一下 Help 中的 A.5.8. Problems with Floating-Point Comparisons 那一段的說明吧。
系統時間:2024-05-04 2:42:55
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!