选择在一列中没有值并且具有相同ID的行

时间:2019-06-18 22:13:54

标签: sql

我有这张桌子:我想获得没有英语的ID。

+----+----------+-------+
| ID | LANGUAGE | NAME  |
+----+----------+-------+
| 1  | english  | james |
+----+----------+-------+
| 1  | french   | john  |
+----+----------+-------+
| 2  | french   | ted   |
+----+----------+-------+
| 3  | german   | tom   |
+----+----------+-------+
| 3  | english  | james |
+----+----------+-------+
| 4  | spanish  | lucy  |
+----+----------+-------+
| 4  | german   | Bud   |
+----+----------+-------+

输出应类似于:

+----+----------+-------+
| ID | LANGUAGE | NAME  |
+----+----------+-------+
| 2  | french   | ted   |
+----+----------+-------+
| 4  | spanish  | lucy  |
+----+----------+-------+
| 4  | german   | Bud   |
+----+----------+-------+

2 个答案:

答案 0 :(得分:1)

子查询会构建语言为英语的所有记录的id字段的列表。

使用它,我们在表中找到所有包含ID不在该列表中的记录。因此,这些是没有英语条目的id记录。

cmap = colors.ListedColormap(["blue", "red", "purple"])
bounds = [0.5,1.5,2.5,3.5]
norm = colors.BoundaryNorm(bounds, cmap.N)

data = np.array([1,2,1,2,2])
sns.heatmap(data.reshape(-1,1), cmap=cmap, norm=norm, annot=True)

答案 1 :(得分:1)

不存在:

select * from tablename t
where not exists (
  select 1 from tablename
  where id = t.id and language = 'english'
)