简体   繁体   English

如何在 Google 表格中使用 GROUP BY 和 TRIM 查询数据?

[英]How can I QUERY data using GROUP BY and TRIM in Google Sheets?

This seems like a simple problem, but I've been googling for hours and haven't had any luck.这似乎是一个简单的问题,但我已经搜索了几个小时并且没有任何运气。

I have some data in column F that has data like: "test", "test ", "", "test1", "test2", "test1 ", " test2", "test1".我在 F 列中有一些数据,其中包含以下数据:“test”、“test”、“”、“test1”、“test2”、“test1”、“test2”、“test1”。

I want to count the number of each value, but I want to TRIM the value so that "test" and "test " get counted as the same.我想计算每个值的数量,但我想修剪该值,以便“test”和“test”被计为相同。

Here is my query:这是我的查询:

=query(F2:F, "select F, count(F) WHERE F <> '' GROUP BY F ORDER BY count(F) DESC LABEL F 'Type', count(F) 'Count'")

I would think it would look something like this, but Google Sheets throws an error:我认为它看起来像这样,但 Google 表格会引发错误:

=query(F2:F, "select trim(F), count(F) WHERE F <> '' GROUP BY trim(F) ORDER BY count(F) DESC LABEL trim(F) 'Type', count(F) 'Count'")

I'm hoping to get rows like this:我希望得到这样的行:

Type    Count
test    2
test1   3
test2   2

You just trim it before the query:您只需在查询之前对其进行修剪:

=ARRAYFORMULA(query(TRIM(F2:F), "select Col1, count(Col1) WHERE Col1 <> '' GROUP BY Col1 ORDER BY count(Col1) DESC LABEL Col1 'Type', count(Col1) 'Count'")

Unfortunately TRIM() is not one of the Scalar functions supported by QUERY()不幸的是,TRIM() 不是 QUERY() 支持的标量函数之一

https://developers.google.com/chart/interactive/docs/querylanguage#scalar_functions https://developers.google.com/chart/interactive/docs/querylanguage#scalar_functions

Without knowing too much about your project, why not have another sheet that references the sheet with the extra spaces and apply the TRIM() function and QUERY() that sheet.在对您的项目了解太多的情况下,为什么不使用另一张表引用带有额外空格的表并应用 TRIM() function 和 QUERY() 该表。

在此处输入图像描述

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

相关问题 在Google表格查询中使用TRIM - Using TRIM in Google Sheet Query 使用 C#,如何将数据从 SQL Server 插入到 Google 表格? - Using C#, how can I insert data from a SQL Server to Google Sheets? 如何在 Google 表格中使用 SQL 查询按子字符串分组 - How to use a SQL query in Google Sheets to group by a substring 如何修剪SQL查询的结果并删除重复项? - How can I trim the results of a sql query, and remove duplicates? 如何修剪Oracle SQL查询中的前缀字符串? - How can I trim a prefix string in an Oracle SQL query? 如何格式化谷歌表格以便正确导出我的数据? - How can I format google sheets so I can export my data properly? 如何在 Google 表格中创建 =Query(query()) Function? - How do I create a =Query(query()) Function in Google Sheets? (GOOGLE SHEETS)如何将 QUERY FUNCTION 的“命名范围”数据参数引用到另一个单元格? - (GOOGLE SHEETS)How do I reference a 'named range' data argument of my QUERY FUNCTION to another cell? 谷歌表格查询 Function。 我怎样才能只获得唯一或不同的行? - Google Sheets Query Function. How can I get only Unique or Distinct Rows? 如何通过修剪 PostgreSQL 中的文本数组来更新数据记录 - How can I update data records by trim a text array in PostgreSQL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM