比较选择在同一表上(mysql)

时间:2018-11-14 23:21:27

标签: mysql select statements

我真的是mysql的新手,我正在尝试做一个简单的选择,但是我不知道为什么。

那就是我所拥有的:

git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   File.ini

no changes added to commit (use "git add" and/or "git commit -a")

ls -al:
-rw-r--r--   1 user  staff   867 15 nov 00:52 File_1.ini
-rw-r--r--   1 user  staff   399 15 nov 00:52 File_2.ini
-rw-r--r--   1 user  staff   900 15 nov 00:52 File_3.ini
-rw-r--r--   1 user  staff   168 15 nov 01:00 file.ini

git config --list --show-origin:
file:.git/config    core.repositoryformatversion=0
file:.git/config    core.autoclrf=false
file:.git/config    core.filemode=true
file:.git/config    core.bare=false
file:.git/config    core.logallrefupdates=true
file:.git/config    core.ignorecase=true
file:.git/config    core.precomposeunicode=true
file:.git/config    remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
file:.git/config    branch.master.remote=origin
file:.git/config    branch.master.merge=refs/heads/master

然后选择代码,在没有在office = china.com上注册代码的办公室。

我必须进行自我连接或类似的操作,或者使用GROUP BY语句? 我被困在这里...我将不胜感激。

2 个答案:

答案 0 :(得分:1)

我想这是可行的

 create table Test(id integer, code integer, office varchar(100));

insert into Test(id, code, office) values(1, 1, "usa"),(2, 2, "usa"),(3, 3, "usa"),(4, 4, "usa"),(5, 5, "usa"),(6, 1, "china"),(7, 3, "china"),(8, 4, "china");

select * from Test;

Select * from Test where code NOT IN (select code from Test where office =   "china");

您已使用子查询。

答案 1 :(得分:1)

您可以在Code上进行“自左联接”,仅考虑在右侧 ie 右侧值{{ 1}}

IS NULL