简体   繁体   English

SQL CountIf 根据平均值从另一列满足条件

[英]SQL CountIf a condition is met from another column based on average

I want to get a count of cells in Column A that meet a criteria (average of 10 minutes or more) in Column B using SQL. Apologies as I'm definitely not an SQL expert.我想使用 SQL 计算 A 列中满足标准(平均 10 分钟或更长时间)的单元格数量。抱歉,我绝对不是 SQL 专家。 Column B has wait times by second and I need to change it to minute, so basically my equation would be Column_B/60, but then also I want to only count the cells in Column A that have an average of 10 minutes or more in Column B. My current formula is below, I know it's off but to give an idea: B 列有等待时间,我需要将其更改为分钟,所以基本上我的等式是 Column_B/60,但我也想只计算 A 列中平均等待 10 分钟或更长时间的单元格B. 我目前的公式如下,我知道它已关闭但给出一个想法:

COUNT(CASE Column_A
WHERE Column_B/60 >= 10)
END

You can try你可以试试

SELECT COUNT(*) FROM table_name WHERE Column_B/60 >= 10;

It can be achieved using the two step process below:可以使用以下两步过程来实现:

1) HH:MM:SS 1) HH:MM:SS

To display Column_B in an HH:MM:SS format, set the Field Type to:要以HH:MM:SS格式显示Column_B ,请将字段类型设置为:

Number > Duration (Sec.)

If required, change the aggregation as required, such as to AVG .如果需要,请根据需要更改聚合,例如更改为AVG

2) CASE Statement 2)案例说明

One way that it can be achieved is by displaying the Column_B value in seconds (60 seconds * 10 minutes):实现它的一种方法是以秒为单位显示Column_B值(60 秒 * 10 分钟):

COUNT(CASE
    WHEN Column_B >= 600 THEN Column_A
    ELSE NULL END)

Google Data Studio Report and a GIF to elaborate: Google Data Studio 报告和 GIF 来详细说明:

暂无
暂无

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

相关问题 根据条件从一列中提取数据并存储在另一列中 - Extracting data from one column and storing in another based on a condition BigQuery 按条件平均列 - BigQuery average column by condition 如何添加一个列,该列根据另一列的条件对其他列的值进行字符串加法 - How to add a column which does a string addition of values from other column based on condition from another column 如何根据 BigQuery 中另一列的条件显示值的计数 - How to show a count of values based on condition of another column in BigQuery 如何在 SQL 中插入新列基于 Window Function 排名和条件 - How to Insert a new Column in SQL based on Window Function Ranking and Condition 大查询/sql 在同一列中维护从下一行开始的相同数据,根据当前行中的某些条件获取 - Big query/sql to maintain the same data from next row onwards in the same column itself, got based on some condition in the current row Bigquery:根据另一个表中设置的条件更新列 - Bigquery: Update column based on condition set in another table 根据 bigquery 中的条件从现有列添加派生列 - Add derived column from existing column based on a condition in bigquery 将列的值与其他列进行比较,并根据条件从第三列中选择值 sql - Compare column's value with other column and base on condition choose value from third column sql SQL - 根据其他列的值重命名一列 - SQL - Rename one column based on values from other columns
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM