使用2个阵列汇总并保留贡献信息
问题
想要汇总行,但仍然保留有关排成最后一笔敬意的信息。
该信息分为两个阵列,但无法弄清楚如何汇总信息并保留信息。
模式&示例数据(简化)
CREATE TABLE A
(
Groupkey Int32,
Sizename String,
Givenqty Array(int),
Category Array(int)
) Engine = Memory ;
INSERT INTO A VALUES (1, 'XS', [1], [154]);
INSERT INTO A VALUES (1, 'M', [1], [154]);
INSERT INTO A VALUES (1, 'L', [1], [154]);
INSERT INTO A VALUES (1, 'XL', [1,1,2,1,1], [145,145,146,154,145]);
SELECT * FROM A:
所需的结果
我想要1个汇总行,其中“ vercyqty pr类别”的总和。
结果应为:(145 = 3,146 = 2,154 = 4):
进行查询时,我知道“类别”列的可能结果,因此我们可以使用此信息来添加值由索引(按类别Number排序)。
类别的数量可以是数据中的随机数,但是在查询数据时已知全范围(如果解决方案需要的话,可以用作帮助数组)。
我已经尝试了不同种类的组隔间,元组等,但似乎无法解决:/
Issue
Want to aggregate rows, but still keep information of how rows tributes to the final sum.
The information is in two arrays, but can't figure out how to aggregate it and keep information.
Schema & sample data (simplified)
CREATE TABLE A
(
Groupkey Int32,
Sizename String,
Givenqty Array(int),
Category Array(int)
) Engine = Memory ;
INSERT INTO A VALUES (1, 'XS', [1], [154]);
INSERT INTO A VALUES (1, 'M', [1], [154]);
INSERT INTO A VALUES (1, 'L', [1], [154]);
INSERT INTO A VALUES (1, 'XL', [1,1,2,1,1], [145,145,146,154,145]);
SELECT * FROM A:
Desired result
I would like 1 aggregated row with the sum of "givenqty pr category".
The result should be: (145 = 3, 146 = 2, 154= 4):
When doing the query I know the possible outcomes of the "Category" column, so we can use this information to add the value by index (sorted by categorynumber).
The number of categories can be random in the data, but the full range is known when querying the data (can be used as a helping array if solution requires it).
I've tried different kinds of groupArray, tuples etc, but can't seem to get I solved :/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用聚合函数 summsap 这样:
Try to use the aggregate function sumMap this way: