简体   繁体   中英

How to get rows WHERE column is less than variable?

I am trying to collect the data that smaller than '80000' for example

SELECT * FROM `apartments` WHERE `building_num`='1' AND `price` < '800000' ORDER by `apartment_num` ASC

in the response printing prices:

1249661,790537,1266228,1267359,1177575

Its showing results that bigger than 800,000 and I did less.

Any one have an idea?

Why are you comparing strings?

 SELECT * FROM `apartments`
 WHERE `building_num`='1' AND `price` < 800000 
 ORDER by `apartment_num` ASC

Unless it's a char column, and then that's another issue.

The reason you're getting this result, is that by the ASCII enconding(which is used when comparing string) , “11” is less then “2” because of the first character .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM