Google sheets 查询以合并两个区域的名称并求其出现次数之和
我有一个与英国各州/地区的阵列。有些区域在此列表中出现多次,因此我执行了一次Google sheets 查询以合并两个区域的名称并求其出现次数之和,google-sheets,google-sheets-formula,google-sheets-query,Google Sheets,Google Sheets Formula,Google Sheets Query,我有一个与英国各州/地区的阵列。有些区域在此列表中出现多次,因此我执行了一次COUNTIF,以确定每个区域出现的次数 现在我需要运行一个查询,列出前5个地区 一般来说,大多数事件发生在伦敦地区 问题是,在这些地区,有两个州指的是大伦敦地区——伦敦和大伦敦 这两个我需要合并并求和它们的值。 只需要一个地区——大伦敦,它的价值需要容纳伦敦和大伦敦的总和 这是我拥有的数据集: +----------------+-------+ | State/Province | count | +--------
COUNTIF
,以确定每个区域出现的次数
现在我需要运行一个查询
,列出前5个地区
一般来说,大多数事件发生在伦敦地区
问题是,在这些地区,有两个州指的是大伦敦地区——伦敦和大伦敦
这两个我需要合并并求和它们的值。
只需要一个地区——大伦敦,它的价值需要容纳伦敦和大伦敦的总和
这是我拥有的数据集:
+----------------+-------+
| State/Province | count |
+----------------+-------+
| Hampshire | 1 |
+----------------+-------+
| Kent | 2 |
+----------------+-------+
| West Lothian | 3 |
+----------------+-------+
| London | 4 |
+----------------+-------+
| Greater London | 5 |
+----------------+-------+
| Cheshire | 6 |
+----------------+-------+
到目前为止,我已经成功地完成了这个查询
:
=查询(A1:B,“按最大(B)描述限制顺序选择A,最大(B)组5标签最大(B)“出现次数”,1)
这给了我这个输出:
+----------------+-----------------------+
| State/Province | Number of occurrences |
+----------------+-----------------------+
| Cheshire | 6 |
+----------------+-----------------------+
| Greater London | 5 |
+----------------+-----------------------+
| London | 4 |
+----------------+-----------------------+
| West Lothian | 3 |
+----------------+-----------------------+
| Kent | 2 |
+----------------+-----------------------+
我需要的是以“大伦敦”的名义合并大伦敦和伦敦条目,并汇总其发生次数,提供以下结果:
+----------------+-----------------------+
| State/Province | Number of occurrences |
+----------------+-----------------------+
| Greater London | 9 |
+----------------+-----------------------+
| Cheshire | 6 |
+----------------+-----------------------+
| West Lothian | 3 |
+----------------+-----------------------+
| Kent | 2 |
+----------------+-----------------------+
| Hampshire | 1 |
+----------------+-----------------------+
很抱歉没有共享工作表,但我有安全限制,不允许我在公司之外共享工作表的任何链接。
@playr0干得好!正确地完成工作。我想问,如何实现另一个列作为s条件?我想的是将
计数限制为在附加列中有1
的记录?…类似的内容,但使用数组公式(替换(如果(
以下两个查询都隐含了部分:={Query({Report\u dataRange}),选择Col24,COUNT(Col24)其中Col27=1 group by Col24 order by Count(Col24)desc limit 5 label Count(Col24)'”,0),查询({Report_dataRange},“Select Count(Col24)group by Col24 order by Count(Col24)desc limit 5 label Col24)'”,0)}
=QUERY(QUERY(ARRAYFORMULA(
{SUBSTITUTE(IF(A1:A="London","♥",A1:A),"♥","Greater London"),B1:B}),
"select Col1, sum(Col2)
where Col1 is not null
group by Col1"),
"select Col1, max(Col2)
group by Col1
order by max(Col2) desc
limit 5
label max(Col2)'Number of occurrences'",1)
=QUERY(ARRAYFORMULA(SUBSTITUTE(
IF((A1:A="London")+(A1:A="London2")+(A1:A="London3"),
"♥",A1:A),"♥","Greater London")),
"select Col1, count(Col1)
where Col1 is not null and not Col1 = '#N/A'
group by Col1
order by count(Col1) desc
limit 5
label count(Col1) 'Number of occurrences'", 1)
=QUERY(ARRAYFORMULA(SUBSTITUTE(
IF((QUERY(A1:B,"where B=1")="London")+
(QUERY(A1:B,"where B=1")="London2")+
(QUERY(A1:B,"where B=1")="London3"),
"♥",QUERY(A1:B,"where B=1")),"♥","Greater London")),
"select Col1, count(Col1)
where Col1 is not NULL and not Col1 = '#N/A'
group by Col1
order by count(Col1) desc
limit 5
label count(Col1) 'Number of occurrences'", 1)