[英]MySQL - Select where both field1 and field2 are greater than 0
I'm trying to do a select query which I select from a table where field1 and field2 are both greater than 0. 我试图做一个选择查询,我从其中field1和field2都大于0的表中选择。
NB field1 & field2 are both INT / NOT NULL. 注意:field1和field2均为INT / NOT NULL。
i've tried doing something along the lines of: 我试着做一些类似的事情:
SELECT * FROM tblname WHERE field1 > "0" AND field2 > "0"
SELECT * FROM tblname WHERE field1 <> "0" AND field2 <> "0"
SELECT * FROM tblname WHERE field1 != "0" AND field2 != "0"
However, when i was just matching whether either or was = 0, this query does work - 但是,当我只是匹配是否为或等于0时,此查询确实有效-
SELECT * FROM tblname WHERE field1 = "0"
I need to check these to produce a list of applicants who've received a grading on their applications, so both field1 and field2 must have been satisfied, so it is assumed that with numerical grading that matching for greater than 0 would work, but for some reason it doesn't? 我需要检查这些内容,以产生一个已收到其应用程序评分的申请人列表,因此field1和field2都必须满足,因此假设在数字评分中,大于0的匹配将起作用,但对于原因不是吗?
For a neater code, you can use LEAST()
which takes the smaller argument placed inside the parantheses . 对于更整洁的代码,可以使用
LEAST()
,它采用放在parantheses内的较小参数。
I believe your problem is that you are comparing ranges on strings instead of numbers( you mentioned those are numeric fields) : 我相信您的问题是您正在比较字符串的范围而不是数字(您提到的是数字字段):
SELECT * FROM YourTable
WHERE LEAST(field1,field2) > 0
If that doesn't solve your problem - edit your question and define "doesn't work" , nothing is being selected? 如果那不能解决您的问题,请编辑您的问题并定义“不起作用”,是否未选择任何内容? Throws an error?
抛出错误? ..
..
您可以尝试以下方法:
SELECT * FROM tblname WHERE field1 <> 0 AND field2 <> 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.