如何获取垂直数据,并根据 Google 表格中的标志列水平提取数据?

How to take vertical data, and extract it horizontally, based on flag column In Google Sheets?

我在 Google 表格中有以下数据格式:

我想根据就绪标志是 Y 还是 N,将数量列提取到 2 个单独的列中。项目名称和大小将是分组依据列,以及就绪标志。以下是查询运行后我想要的数据格式:

还没有尝试过任何解决方案,因为我已经离开编程循环很长时间了,对 SQL 非常生疏。

={"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))}}

您也可以将其用作枢轴 table - 效果很好。项目名称和尺寸按行输入,准备好了吗?作为列和 sum(Quantity) 作为值。

或者确实作为数据透视查询

=QUERY(A:D,"SELECT A,B,sum(C) where A<>'' group by A,B pivot D ")
=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))