如何在SQL中使用NOT IN?

时间:2017-04-24 03:54:21

标签: mysql sql join notin

package edu.stanford.nlp.examples;

import edu.stanford.nlp.util.*;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.pipeline.*;

import java.util.*;


public class TokensRegexExampleTwo {

  public static void main(String[] args) {

    // set up properties
    Properties props = new Properties();
    props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,tokensregex");
    props.setProperty("tokensregex.rules", "multi-step-per-org.rules");
    props.setProperty("tokensregex.caseInsensitive", "true");

    // set up pipeline
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

    // set up text to annotate
    Annotation annotation = new Annotation("...text to annotate...");

    // annotate text
    pipeline.annotate(annotation);

    // print out found entities
    for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
      for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
        System.out.println(token.word() + "\t" + token.ner());
      }
    }
  }
}

这是我的关系架构,我正在尝试返回参与游戏但尚未获胜的参与者名单...

所以,我有

  1. 收集了所有名字,
  2. 删除了因不存在而赢得所有名字的人
  3. 删除了所有抽奖名称
  4. 但是我无法消除那些没有参与游戏的人,但仍然是参与者名单栏。

    这部分代码无效

    Game(p1, p2, pointsp1, pointsp2, ),
    Participant(name, club, age)
    
    FK Game(p1) references Participant(name),
    FK Game(p2) references participant(name)
    

    这是我的完整代码:

    { 
    SELECT name 
    FROM Participant 
    JOIN Game 
    WHERE Participant.name!=Game.p1 
        OR Participant.name!=Game.p2
    }
    

2 个答案:

答案 0 :(得分:0)

假设您只想要参与游戏但未获胜的参赛者名单,请尝试此操作。

{{1}}

第一个子选择获得所有获胜者(并忽略关系),第二个选择获得所有游戏中的所有参与者。这不是完成任务的好方法,但它会起作用。

答案 1 :(得分:0)

你可以像下面这样。

SELECT name 
FROM Participant P
WHERE name NOT IN (
    SELECT DISTINCT p1
    FROM   Game G
    WHERE  pointsp1 > pointsp2
    UNION ALL
    SELECT DISTINCT p2
    FROM   Game G
    WHERE  pointsp1 < pointsp2
    UNION ALL
    SELECT ender
    FROM   Game G
    WHERE  pointsp1 = pointsp2
    UNION ALL
    SELECT starter
    FROM   Game G
    WHERE  pointsp1 = pointsp2)
OR  name not in (
    select p1 from game
    union all
    select p2 from game
)
相关问题