mysql表中有两个int字段 apples 以及 bananas . 我想选择苹果=香蕉+2的所有行(结果是2、4或122124或10201022等)。我试过了 "SELECT * FROM tablename WHERE apples=bananas+2" , "SELECT *,bananas+2 AS bans FROM tablename WHERE apples=bans" 但连续返回空和“无禁止字段”错误。有什么想法吗?
apples
bananas
"SELECT * FROM tablename WHERE apples=bananas+2"
"SELECT *,bananas+2 AS bans FROM tablename WHERE apples=bans"
5cnsuln71#
如果你需要排在哪里 apples = bananas + 2 ,你可能想 where apples = bananas - 2 ,或 where bananas = apples + 2 .另外,请记住检查字段的类型,因为如果 unsigned 你最好用加法而不是减法,那样会导致错误。
apples = bananas + 2
where apples = bananas - 2
where bananas = apples + 2
unsigned
1条答案
按热度按时间5cnsuln71#
如果你需要排在哪里
apples = bananas + 2
,你可能想where apples = bananas - 2
,或where bananas = apples + 2
.另外,请记住检查字段的类型,因为如果
unsigned
你最好用加法而不是减法,那样会导致错误。