简体   繁体   English

MySQL查询无法正常工作。 没有给出预期的结果

[英]MySQL query not working. not giving expected result

I have a database where there are 4 field to do query. 我有一个数据库,其中有4个字段可以查询。

  1. topup 充值
  2. totala 总体
  3. totalb 合计
  4. totalc 合计

I am running the mysql query which is supposed to return 4 rows. 我正在运行mysql查询,应该返回4行。 But returning nothing. 但是什么也没返回。 Following is my query: 以下是我的查询:

$qry=mysql_query("SELECT id FROM ".user." WHERE `topup` >'0' AND `totala`>='9' AND  `totalb`>='9' AND  `totalc`>='9'");
while($res=mysql_fetch_row($qry)){
    echo $res['0'];
}

what is the wrong? 怎么了 And main problem is if I run any one query 主要问题是我是否运行任何一个查询

eg: WHERE totala >='9' 例如:WHERE totala > ='9'

then it is working, but not taking all query 然后就可以了,但不能接受所有查询

Your query will fetch rows in which all your condition are true simultaneously. 您的查询将同时获取所有条件都为真的行。

It will fetch the row with topup = 1 and totala = 10 and totalb = 10 and totalc = 10 but won't fetch the row topup = 0 and totala = 10 and totalb = 10 and totalc = 10 because of topup not greater than zero. 它将获取topup = 1且totala = 10且totalb = 10且totalc = 10的行,但由于topup不大于零,因此将不会获取topup = 0且totala = 10且totalb = 10且totalc = 10的行。 。

If you want to fetch row with ANY of this condition you need to use OR statement instead of AND. 如果要使用此条件的ANY来获取行,则需要使用OR语句代替AND。

$qry=mysql_query("SELECT id FROM ".user." WHERE `topup` >'0' OR `totala`>='9' OR `totalb`>='9' OR `totalc`>='9'");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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