關於mysql float型別欄位比較 不準的問題
阿新 • • 發佈:2019-01-31
這裡的cx_mode表中的guideprice是float型別,
qys_data表中的qys_avgprice是int(11)型別
####錯誤的sql語句
select a.provinceid,a.cityid,a.modeid,a.qys_avgprice,cast(b.guideprice as decimal(10,2))*10000
from qys_data a
left join cx_mode b on a.modeid=b.modeid
where a.provinceid>0 and a.cityid=-1
####正確的sql語句
select a.provinceid,a.cityid,a.modeid,a.qys_avgprice,cast(b.guideprice as decimal(10,2))*10000
from qys_data a
left join cx_mode b on a.modeid=b.modeid
where a.provinceid>0 and a.cityid=-1
qys_data表中的qys_avgprice是int(11)型別
有一條記錄a:qys_avgprice 266500,guideprice 25.65
####錯誤的sql語句
select a.provinceid,a.cityid,a.modeid,a.qys_avgprice,cast(b.guideprice as decimal(10,2))*10000
from qys_data a
left join cx_mode b on a.modeid=b.modeid
where a.provinceid>0 and a.cityid=-1
and a.qys_avgprice>b.guideprice*10000;
結果:會出現記錄a
####正確的sql語句
select a.provinceid,a.cityid,a.modeid,a.qys_avgprice,cast(b.guideprice as decimal(10,2))*10000
from qys_data a
left join cx_mode b on a.modeid=b.modeid
where a.provinceid>0 and a.cityid=-1
and a.qys_avgprice>cast(b.guideprice as decimal(10,2))*10000;
結果:不會出現記錄a