Google 查询语言:根据每列的条件计算多列并按日期分组
Google Query Language: Count multiple columns based on conditions for each column and grouped by date
我想在 Google 工作表中使用 QUERY 函数/Google 查询语言,根据每个列的条件并按日期分组对多个列进行计数。
这是数据库的样子(它是发送的电子邮件列表,带有时间戳和关于它们是否被打开和点击的信息):
date
opened
clicked
2021-09-14 4:30:06
TRUE
FALSE
2021-09-14 4:30:10
TRUE
TRUE
2021-09-15 4:30:10
FALSE
FALSE
2021-09-15 4:30:11
TRUE
TRUE
2021-09-15 4:30:18
FALSE
FALSE
这是我需要的结果(我基本上想知道每天打开和点击了多少封电子邮件):
date
count opened
count clicked
2021-09-14
2
1
2021-09-15
1
1
我知道我可以使用以下查询为一列实现此目的:
select
toDate(A),
count(B) where B=TRUE
group by toDate(A)
但如果我尝试将查询应用于两列,它就不起作用:
select
toDate(K),
count(B) where B=TRUE,
count(C) where C=TRUE
group by toDate(K)
是否有使用单一公式实现此目的的优雅方法?
您可以将查询输入中的数据转换为您想要的类型 - 在这种情况下,只需从 table
中删除所有 FALSE
值
=(query(ARRAYFORMULA({A:A,SUBSTITUTE(B:C,"FALSE","")}), "select toDate(Col1),count(Col2),count(Col3) where Col1 is not null group by toDate(Col1)"))
我想在 Google 工作表中使用 QUERY 函数/Google 查询语言,根据每个列的条件并按日期分组对多个列进行计数。
这是数据库的样子(它是发送的电子邮件列表,带有时间戳和关于它们是否被打开和点击的信息):
date | opened | clicked |
---|---|---|
2021-09-14 4:30:06 | TRUE | FALSE |
2021-09-14 4:30:10 | TRUE | TRUE |
2021-09-15 4:30:10 | FALSE | FALSE |
2021-09-15 4:30:11 | TRUE | TRUE |
2021-09-15 4:30:18 | FALSE | FALSE |
这是我需要的结果(我基本上想知道每天打开和点击了多少封电子邮件):
date | count opened | count clicked |
---|---|---|
2021-09-14 | 2 | 1 |
2021-09-15 | 1 | 1 |
我知道我可以使用以下查询为一列实现此目的:
select
toDate(A),
count(B) where B=TRUE
group by toDate(A)
但如果我尝试将查询应用于两列,它就不起作用:
select
toDate(K),
count(B) where B=TRUE,
count(C) where C=TRUE
group by toDate(K)
是否有使用单一公式实现此目的的优雅方法?
您可以将查询输入中的数据转换为您想要的类型 - 在这种情况下,只需从 table
中删除所有FALSE
值
=(query(ARRAYFORMULA({A:A,SUBSTITUTE(B:C,"FALSE","")}), "select toDate(Col1),count(Col2),count(Col3) where Col1 is not null group by toDate(Col1)"))