如何计算基于相邻单元格的文本字符串?

How can I count text strings based on adjacent cell?

我在 Google 表格中有一个单元格网格:

A1在B1显示商品编码"ABC"的数量,C1则显示商品编码"DEF"[的数量=21=] 在 D1 中,然后在下一行为下一位客户重复,依此类推。
我试图使用某种 COUNT 公式在底部一次总结所有这些区域,但还没有弄清楚如何做。

=QUERY({A:B;C:D}, 
 "select Col2, sum(Col1) 
  where Col1 is not null 
  group by Col2
  label sum(Col1)'Sumary', Col2'Item'")

=QUERY({A:B;C:D}, 
 "select Col2, count(Col2) 
  where Col2 is not null 
  group by Col2
  label count(Col2)'Count', Col2'Item'")