0

这应该相当简单,但是在搜索时找到要使用的正确术语很棘手。

WHERE lang='en'在下面的查询中,我只需要选择不WHERE lang='nl_NL'返回任何内容。换句话说,我想查找所有记录WHERE script='generic',优先级为lang=nl_NL

SELECT * FROM international WHERE script='generic' AND (lang = 'nl_NL' OR lang = 'en')
4

2 回答 2

2
SELECT * FROM international WHERE script = 'generic' AND lang = CASE
  WHEN EXISTS(
    SELECT 1
    FROM   international
    WHERE  script = 'generic'
       AND lang   = 'nl_NL'
    LIMIT  1
  ) THEN 'nl_NL'
  ELSE 'en'
END
于 2013-02-04T18:49:09.853 回答
1

这是获取指定结果集的一种方式的示例:

SELECT i.*
  FROM international i
 WHERE i.lang = 'nl_NL'
    OR (i.lang = 'en' 
        AND NOT EXISTS 
        (SELECT 1 FROM international d WHERE d.lang = 'nl_NL')
       )

当您希望应用“ script='generic'”谓词时,您的问题尚不清楚。

SELECT i.*
  FROM international i
 WHERE ( i.script = 'generic' AND i.lang = 'nl_NL')
    OR ( i.script = 'generic' AND i.lang = 'en'
         AND NOT EXISTS 
           ( SELECT 1
               FROM international d
              WHERE d.lang = 'nl_NL'
                AND d.script='generic'
           )
       )
于 2013-02-04T18:51:02.227 回答