[英]mysql not returning proper results for this query
Hi I have a column km ( varchar ) in a table called products and and we save km values like how much a car has been driven. 嗨,我在名为product的表中有一列km(varchar),我们保存了km的值,例如汽车的行驶量。 So a km could be any number that is saved.
因此,公里可以是保存的任何数字。 Now I want to query this column like I want results where km from 100 to 1000.
现在,我想查询此列,就像我想要km从100到1000的结果一样。
so the query looks like this 所以查询看起来像这样
SELECT *
FROM products1
WHERE categories_category_id = 1
AND subsubCategoryId = 1026
AND subcat = 174
AND categoryAdvertiseTypeId = 0
AND km >= 1000
AND km <= 5000
LIMIT 50
but what is happening is I get km not from this range. 但是正在发生的事情是我不在这个范围内。 dont know why.
不知道为什么。 Please tell me what could be the issue.
请告诉我可能是什么问题。
Cast your kilometer km
column to a number and then do the comparison. 将公里数
km
列转换为数字,然后进行比较。
SELECT *
FROM products1
WHERE
categories_category_id = '1' AND
subsubCategoryId = '1026' AND
subcat = '174' AND
categoryAdvertiseTypeId = '0' AND
CAST(km AS UNSIGNED) BETWEEN 1000 AND 5000
LIMIT 50
On the cosmetic side of things, I removed all those unnecessary backticks, which are ugly and make the query hard to read. 在外观方面,我删除了所有不必要的反引号,这些引号很难看,使查询难以阅读。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.