MySQL greater than or equal to operator is ignoring its or equal to obligation

前端 未结 2 2026
渐次进展
渐次进展 2021-02-15 10:06

If a price in a row is 38.03, then the following search restrictions should all return the row containg the result.

WHERE price >= \'38.02\' AND pr

相关标签:
2条回答
  • 2021-02-15 10:38

    keep in mind that float is a flawed data type when it comes to precision. If you represent 12 as float, you will get 11.99999999999998 or something.

    '38.03' can be converted to decimal, or other data type that is more precise (depending on RDBMS, I am being general here), and it will differ from the float value.

    float is 32 bit, low precision. Double works a lot better, being 64 bit data type. Decimal data type in some systems are 128 bit numeric data types for storing very precise numeric values, and is usually used for denominating money.

    And, skip the habit of comparing using the = operator, of float values. Floats are used for approximate and fast calculations, and only comparison with a range is acceptable for checking the value of a float. That's valid for basically every single system.

    0 讨论(0)
  • 2021-02-15 10:42

    When you use quotes (') your variables will be treated as strings. I think thats your problem.

    Try: WHERE price >= 38.03 AND price <= 38.03

    0 讨论(0)
提交回复
热议问题