Google sheets 如何根据Google Sheets中的flag列获取垂直数据并水平提取?
我在谷歌表单中有以下数据格式: 我想根据就绪标志是Y还是N将Quantity列提取为两个单独的列。项目名称和大小将是group By列,以及就绪标志。以下是查询运行后我想要的数据格式: 我还没有尝试过任何解决方案,因为我已经脱离编程循环很长一段时间了,对SQL非常生疏Google sheets 如何根据Google Sheets中的flag列获取垂直数据并水平提取?,google-sheets,subquery,pivot-table,aggregation,Google Sheets,Subquery,Pivot Table,Aggregation,我在谷歌表单中有以下数据格式: 我想根据就绪标志是Y还是N将Quantity列提取为两个单独的列。项目名称和大小将是group By列,以及就绪标志。以下是查询运行后我想要的数据格式: 我还没有尝试过任何解决方案,因为我已经脱离编程循环很长一段时间了,对SQL非常生疏 ={"Item name", "Size", "Not ready", "Ready"; {QUERY(QUERY(QUERY(A2:D, "select *", 0), "select Col1, Col2,
={"Item name", "Size", "Not ready", "Ready";
{QUERY(QUERY(QUERY(A2:D,
"select *", 0),
"select Col1, Col2, count(Col1)
where Col2 is not null
group by Col1, Col2
order by Col1 desc
label count(Col1)''", 0),
"select Col1, Col2", 0),
ARRAYFORMULA(ARRAY_CONSTRAIN(IFERROR(VLOOKUP(QUERY(QUERY(QUERY(A2:D,
"select *", 0),
"select Col1, Col2, count(Col1)
where Col2 is not null
group by Col1, Col2
order by Col1 desc
label count(Col1)''", 0),
"select Col1", 0)&
QUERY(QUERY(QUERY(A2:D,
"select *", 0),
"select Col1, Col2, count(Col1)
where Col2 is not null
group by Col1, Col2
order by Col1 desc
label count(Col1)''", 0),
"select Col2", 0),
QUERY(QUERY({A2:A&B2:B, C2:D},
"select *", 0),
"select Col1, Col2, Col3
where Col3='N'", 0), 2, 0), 0),
COUNTA(QUERY(QUERY(QUERY(A2:D,
"select *", 0),
"select Col1, Col2, count(Col1)
where Col2 is not null
group by Col1, Col2
order by Col1 desc
label count(Col1)''", 0),
"select Col1,Col2", 0))/2, 1)),
ARRAYFORMULA(ARRAY_CONSTRAIN(IFERROR(VLOOKUP(QUERY(QUERY(QUERY(A2:D,
"select *", 0),
"select Col1, Col2, count(Col1)
where Col2 is not null
group by Col1, Col2
order by Col1 desc
label count(Col1)''", 0),
"select Col1", 0)&
QUERY(QUERY(QUERY(A2:D,
"select *", 0),
"select Col1, Col2, count(Col1)
where Col2 is not null
group by Col1, Col2
order by Col1 desc
label count(Col1)''", 0),
"select Col2", 0),
QUERY(QUERY({A2:A&B2:B, C2:D},
"select *", 0),
"select Col1, Col2, Col3
where Col3='Y'", 0), 2, 0), 0),
COUNTA(QUERY(QUERY(QUERY(A2:D,
"select *", 0),
"select Col1, Col2, count(Col1)
where Col2 is not null
group by Col1, Col2
order by Col1 desc
label count(Col1)''", 0),
"select Col1,Col2", 0))/2, 1))}}
您也可以将其作为数据透视表来执行-效果相当不错。项目名称和大小作为行输入,准备好了吗?作为列,总和(数量)作为值 或者确实是一个pivot查询
=QUERY(A:D,"SELECT A,B,sum(C) where A<>'' group by A,B pivot D ")
=QUERY(A:D,“选择A,B,sum(C),其中A''按A,B和D分组”)
=ARRAYFORMULA(如果不是)是空的(查询,
“选择*”,1),
选择Col1、Col2、sum(Col3)
其中Col1“
按Col1、Col2分组
支点Col4
按Col1 desc“1”)订购,
查询(查询)查询(A1:D,
“选择*”,1),
选择Col1、Col2、sum(Col3)
其中Col1“
按Col1、Col2分组
支点Col4
Col1 desc“1号订单),
“选择*
标签Col3“未就绪”,Col4“就绪”,1),0)
我认为单一的公式解决方案确实很难——无法想出一个替代方案,来替代group by query后面跟着Vlookup的一些变体。不过,我会发布一个轴心作为替代。这是可行的,但另一个答案显示了更大的灵活性,所以我选择了它作为选择的答案。这仍然有助于人们展望未来。
=ARRAYFORMULA(IF(NOT(ISBLANK(QUERY(QUERY(A1:D,
"select *", 1),
"select Col1, Col2, sum(Col3)
where Col1 <> ''
group by Col1, Col2
pivot Col4
order by Col1 desc", 1))),
QUERY(QUERY(QUERY(A1:D,
"select *", 1),
"select Col1, Col2, sum(Col3)
where Col1 <> ''
group by Col1, Col2
pivot Col4
order by Col1 desc", 1),
"select *
label Col3 'Not ready', Col4 'Ready'", 1), 0))