两个OR语句MySQL查询

时间:2015-09-02 06:32:48

标签: mysql sql

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div style="width:980px;margin-left:auto;margin-right:auto;border-radius:25px;background-color: #ffffff;">
  <form class="form-group" id="email" method="post" name="email" style="width:380px; padding:20px;">
    <div class="form-group">
      <label>
        <input id="showInline" type="checkbox" value="" checked>
        <strong>Show as HTML Code</strong>
      </label>
    </div>
  </form>
</div>

这是选择SELECT b_id,b_thumb1,b_thumb2,b_league,b_date,b_status FROM battles WHERE b_userid1=? OR b_userid2=? AND b_status=1 OR b_status=2 ORDER BY b_date DESC 而非b_status = 01的行。有人能指出我正确的方向吗?

2 个答案:

答案 0 :(得分:1)

我猜您应该将TimerTask doAsynchronousTask = new TimerTask() { @Override public void run() { //Perform background work here handler.post(new Runnable() { public void run() { //Perform GUI updation work here // increase radius with your method } }); } }; timer.schedule(doAsynchronousTask, 1, 1000); 添加到()语句。

where

SELECT b_id,b_thumb1,b_thumb2,b_league,b_date,b_status FROM battles WHERE (b_userid1=? OR b_userid2=?) AND (b_status=1 OR b_status=2) ORDER BY b_date DESC 提出一些建议,使用SQL语句替换多个IN语句。

OR

答案 1 :(得分:0)

SELECT b_id,b_thumb2,b_league,b_date,b_status 
FROM battles 
WHERE (b_userid1=? OR b_userid2=?) 
AND (b_status=1 OR b_status=2) 
ORDER BY b_date DESC 

这将给出一个结果,其中b_userid等于两个参数之一,状态为1或2.

SELECT b_id,b_thumb2,b_league,b_date,b_status 
FROM battles 
WHERE b_userid1=? OR b_userid2=?
AND b_status=1 OR b_status=2 
ORDER BY b_date DESC 

这将返回b_userid1等于第一个参数或b_userid2等于第二个参数且status = 1或b_status = 2的结果(可能,sql上的操作顺序很难)。

所以它等于:

SELECT b_id,b_thumb2,b_league,b_date,b_status 
FROM battles 
WHERE (b_userid1=?) OR (b_userid2=? 
AND b_status=1) OR (b_status=2) 
ORDER BY b_date DESC

这不是你想要的。