简体   繁体   English

按两列中的值过滤

[英]Filter by a value in two columns

My table looks like this我的桌子看起来像这样

Team团队 Language People人们
Team A A组 English英语 3 3
Team B B组 English英语 4 4
Team B B组 Spanish西班牙语 3 3
Team Spanish西班牙队 Spanish西班牙语 4 4
Team C团队 C Portuguese葡萄牙语 4 4

If you notice, Team B handles English and Spanish and there's also a Team Spanish .如果您注意到, Team B处理英语和西班牙语,还有一个Team Spanish

I want to combine Team Spanish with Team B - Spanish , so it only shows one row with the sum of 7 people.我想将Team SpanishTeam B - Spanish结合起来,所以它只显示一行,总和为 7 人。

My expected result:我的预期结果:

Team团队 Language People人们
Team Spanish西班牙队 Spanish西班牙语 7 7

My workaround is to create an extra column, combine the Team column with the Language column and then sum the results我的解决方法是创建一个额外的列,将Team列与Language列结合起来,然后对结果求和

SUMIF(people, aux_col IN ('team B - Spanish', 'Team Spanish - Spanish')) AS new_people_count  

Never mind the last code, it's just pseudocode别管最后的代码,它只是伪代码

i made my calculation using google sheet.我使用谷歌表格进行了计算。 I think you must complete your goal in two steps: First step Create a table like your original table.我认为你必须分两步完成你的目标: 第一步 创建一个像你原来的表一样的表。 This is the original table in google sheet Original Table .这是 google sheet Original Table中的原始表格。 In the new table write the headers and the under the TEAM column write this formula =if (B3<>"Spanish";A3;"Team Spanish") copy this formula in rows from 4 to 7. Under the column LANGUAGE and PEOPLE copy the exact value of the original table example for LANGUAGE column write =B3 and copy from this formula in rows from 4 to 7. example for PEOPLE column write =C3 and copy from this formula in rows from 4 to 7. At the end you will have this table: Table step 1在新表中写入标题,并在 TEAM 列下写入此公式 =if (B3<>"Spanish";A3;"Team Spanish") 将此公式复制到第 4 到 7 行中。在 LANGUAGE 和 PEOPLE 列下复制LANGUAGE 列的原始表示例的确切值写入 =B3 并从此公式中复制第 4 到 7 行。PEOPLE 列的示例写入 =C3 并从此公式中复制第 4 到 7 行。最后,您将有这个表:表步骤 1

finally you have to pivot the previous table.最后你必须上表 pivot。 in the rows put TEAM and LANGUAGE.在行中放置 TEAM 和 LANGUAGE。 Don't pu anything in column SUM of PEOPLE.不要在 PEOPLE 的 SUM 列中添加任何内容。 And here you have your final table Final Table在这里你有你的决赛桌决赛桌

Let me know if that is what you wanted to do.让我知道这是否是您想要做的。 bye再见

Using your query which has a condition changes all Team B-Spanish to Team Spanish I also added the count function that added (sum()) of people and produced the Expected output:使用具有条件的查询将所有 Team B-Spanish 更改为 Team Spanish 我还添加了计数 function,该计数添加了 (sum()) 人员并产生了预期的 output:

WITH Sample AS
 (SELECT 'Team A' as Team, "English" as Language, 3 as People UNION ALL
  SELECT 'Team B', "English", 4 UNION ALL
  SELECT 'Team B', "Spanish", 3 UNION ALL
  SELECT 'Team Spanish', "Spanish", 4 UNION ALL
  SELECT 'Team C', "Portuguese", 4)

SELECT Language, CASE
WHEN CONCAT(Team, '-', Language) = 'Team B-Spanish' THEN 'Team Spanish'
ELSE Team
END AS Team,
SUM (People) as People
From Sample where Language = "Spanish" GROUP BY Team, Language 

Output: Output: 在此处输入图像描述

I was overcomplicating my idea... This code solves the issue我的想法过于复杂了......这段代码解决了这个问题

CASE
WHEN CONCAT(team, '-', language) = 'Team B-Spanish' THEN 'Team Spanish'
ELSE team
END AS team,

in SQL you can run a query like this:在 SQL 中,您可以运行如下查询:

select case when Language="Spanish" then "Team Spanish" else Team end as Team, Language, sum(People) from myTable group by Team, Language select case when Language="Spanish" then "Team Spanish" else Team end as Team, Language, sum(People) from myTable group by Team, Language

Let me know if this can be a solution for you.让我知道这是否可以成为您的解决方案。

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

相关问题 Google Datastudio:为日期源的两个不同日期列应用日期范围过滤器 - Google Datastudio: Apply Date Range Filter for Two Different Date Columns of Date Source select 行的值与第二个表中的两列之一匹配: - select rows whose value matches with either of the two columns in the second table: 对两个不同的数据源使用相同的过滤器控件 - Using the same filter control for two different data sources 如何使用 snapshotChanges() 方法获取键值和过滤数据? - How to use snapshotChanges() method to get both key value and filter the data? SQL/BigQuery - 如何消除基于两列的重复项 - SQL/BigQuery - How to eliminate duplicates based on two columns 如何仅使用值进行过滤,而不管 AWS CLI 中的名称 - How to filter with value only regardless the name in AWS CLI 如何使用 Reactjs 按参考值过滤 Firestore 特定集合的文档数据 - How to filter Firestore specific collection's doc data by its reference value with Reactjs 在 BigQuery 表中按行有效地外部连接两个数组列 - Efficiently outer join two array columns row-wise in BigQuery table 我能够对值上的变量应用 firebase 实时数据库查询 我想对同一个变量应用两个值的查询 - I am able to aply firebase realtime database query for on variable on value i want to apply query for two values to the same variable 如何使用过滤器循环? - How to loop with a filter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM