如何获取谷歌电子表格中2列中不常见的条目

时间:2016-07-22 06:53:27

标签: sql google-sheets

如何使用QUERY()获取Google电子表格中2列中不常见的条目。请注意,每列只有唯一的条目。

另请注意,我没有使用Excel,但是在google工作表上,但是SQL查询可能会有用,因为工作表支持QUERY。

例如:

G   H
a   a 
b   c
ca  cx
d   d
e   l
f   b

输出必须是:

c
ca
cx
e
f
l

2 个答案:

答案 0 :(得分:1)

假设您的数据位于G和H列(从第2行开始),请尝试

=query(ArrayFormula(query({G2:G;H2:H}&{"",""}, "Select Col1, count(Col2) where Col1 <>'' group by Col1")), "Select Col1 where Col2 < 2")

或者,FILTER也应该工作

={filter(G2:G8, isna(match(G2:G8,H2:H8,0))); filter(H2:H8, isna(match(H2:H8,G2:G8,0)))}

答案 1 :(得分:-1)

SQL

我们创建一个表条目,您的数据分为两列( entry1 entry2 ),然后我们可以从两个列中获取不常见的条目使用以下查询的列:

select entry2 from entries where entry2 not in (select entry1 from entries) UNION
select entry1 from entries where entry1 not in (select entry2 from entries);