[英]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.