0

私はこのクエリを持っています:

select  feature_requests.*,
from    feature_requests
where   feature_requests.status in ('open','closed','indevelopment')

私には別のステータスもあります-拒否されました。

ステータスが拒否されたすべての行も選択する必要がありますが、機能要求テーブルの別の列は何かに等しい必要があります。

だから、これを行うもの:

select  feature_requests.*,
from    feature_requests
where   feature_requests.status in ('open','closed','indevelopment','denied') and
        if status = denied, instance_id = ?

正しい構文がわからない。助けてくれてありがとう:)

4

3 に答える 3

0

これはうまくいくはずです:

SELECT
  feature_requests.*
FROM
  feature_requests
WHERE
  feature_requests.status IN ('open','closed','indevelopment') OR (
    feature_requests.status='denied' AND
    instance_id=?
  )

これは、次のように使用している唯一のテーブルである場合、テーブル名を何度もリストせずに記述することもできます。

SELECT
  *
FROM
  feature_requests
WHERE
  status IN ('open','closed','indevelopment') OR (
    status='denied' AND
    instance_id=?
  )

where 句でANDand/orを使用する場合は、 andの間で何が優先されるかがわかっている場合でも、括弧を使用して実際の意味を示すことを忘れないでください。MySQl での演算子の優先順位の詳細については、次の例を参照してください。OR( )ANDOR

color=blue AND shape=circle OR type=ball

意味

(color=blue AND shape=cirlce) OR type=ball

しかし、次のように簡単に誤解される可能性があります

color=blue AND (shape=circle OR type=ball)
于 2013-08-26T02:36:27.237 に答える
0

さびた記憶から、あなたはおそらくこのようなものを望んでいます

SELECT feature_requests.* FROM feature_requests 
WHERE feature_requests.status IN ('open', 'closed', 'indevelopment') OR
  (feature_requests.status='denied' AND instance_id = ???)

あなたが今持っているものはかなり近いです。

http://www.tutorialspoint.com/sql/sql-and-or-clauses.htm

于 2013-08-26T02:38:33.287 に答える