简体   繁体   English

如何查询谷歌表格中独特功能的数量?

[英]How to query count of unique features in google sheets?

I have this table:我有这张桌子:

Name    | Age
Ann     | adult
Ann     | adult
Andrew  | adult
Mike    | adult
Ann     | teenager
John    | teenager
John    | teenager

I want this output:我想要这个 output:

Age      | count Name (distinct Names)
adult    |  3
teenager |  2

Unfortunately, I can't go further then this formula:不幸的是,我不能再 go 然后这个公式:

=QUERY(table; "select B, count(A) group by B"; 1)

where the 'table' is the named range with input data.其中“表”是具有输入数据的命名范围。 And it gives me this:它给了我这个:

Age      | count Name
adult    |  4
teenager |  3

I need something like:我需要类似的东西:

=QUERY(table; "select B, count(unique(A)) group by A"; 1)

which obviously doesn't work.这显然是行不通的。

So, how can I achieve my target output with quering?那么,我怎样才能通过查询来实现我的目标 output 呢? I know, I can do that with pivot tables with countunique function, but I want to go without pivot tables.我知道,我可以使用带有 countunique function 的 pivot 表来做到这一点,但我想在没有 pivot 表的情况下使用 go。

One option could be QUERY + UNIQUE :一种选择可能是QUERY + UNIQUE

=QUERY(UNIQUE(A2:B),"SELECT Col2, COUNT(Col1) WHERE Col2 IS NOT NULL GROUP BY Col2")

在此处输入图像描述

You can also make use of this formula:你也可以使用这个公式:

=ARRAYFORMULA(QUERY(UNIQUE({B:B, B:B & A:A, A:A}), "SELECT Col1, COUNT(Col1) WHERE Col1 IS NOT NULL GROUP BY Col1 ORDER BY COUNT(Col1) DESC LABEL COUNT(Col1)'count Name'", 1))

After

使用查询后

Explanation解释

The formula makes use of the following functions:该公式使用以下函数:

  • ARRAYFORMULA

  • UNIQUE

  • QUERY

In order to find the unique values, the UNIQUE is used for the range needed for the query ( A:B ) such that the sorting and counting is done on this range.为了找到唯一值, UNIQUE用于查询所需的范围 ( A:B ),以便在此范围内完成排序和计数。 The LABEL is used as well in order to set the header name for the resulted column. LABEL也用于为结果列设置 header 名称。

Reference参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google表格计数(如果唯一且包含) - Google Sheets Count if unique & contains 计算 Google 表格中唯一日期的唯一值 - Count unique values for unique dates in Google Sheets 谷歌表查询唯一范围 - Google sheets query on unique range Google 表格 - 将查询与计数一起使用 - Google Sheets - Using Query with Count 如何使用谷歌表格查询和求和唯一值 - How to query and sum unique values using google Sheets Google 表格对电子表格的所有列的计数都是唯一的 - Google Sheets count unique for all columns of a spreadsheet Google表格 - 计算QUERY函数(或任何其他函数,但不使用数据透视表)中的唯一/不同值 - Google Sheets - Count unique / distinct values within QUERY function (or any other function, but not using pivot table) 将 order by 添加到查询公式中,该公式从 Google 表格列中的分隔字符串中获取唯一列表和计数 - add order by to query formula that gets unique list and count from delimited strings in a column Google sheets 如何将此 SQL 查询翻译成谷歌表格以计算多个值 - How to translate this SQL query into google sheets to count multiple values 如何计算 2 列中的唯一对并使用 Google 表格中的 ArrayFormula 使用计数进行排序? - How to count the unique pairs in 2 columns and sort using the count using an ArrayFormula in Google Sheets?
 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM