Netezza 聚合问题(枢轴)
我正在使用 Netezza 生成报告,并且有以下查询
select b.group_name,a.group_id, PASS_FAIL, COUNT(*) from log a
join group b on a.group_id=b.group_id
group by b.group_name,a.group_id, PASS_FAIL
它会收集有关表中通过和失败次数的信息,如下所示:
GROUP_NAME GROUP_ID PASS_FAIL COUNT
GROUP1 4 FAIL 382
GROUP1 4 PASS 339
如何更改查询以便可以使用 PASS 和 FAIL 作为列。
GROUP_NAME GROUP_ID PASS FAIL
GROUP1 4 339 382
Netezza 中不提供 Pivot,因此我想知道解决此问题的最佳方法是什么。最好的方法是什么?
I'm using Netezza to generate a report and I have the following query
select b.group_name,a.group_id, PASS_FAIL, COUNT(*) from log a
join group b on a.group_id=b.group_id
group by b.group_name,a.group_id, PASS_FAIL
It collects information on the number of passes and failures in a table like this:
GROUP_NAME GROUP_ID PASS_FAIL COUNT
GROUP1 4 FAIL 382
GROUP1 4 PASS 339
How can I change the query so that I can use PASS and FAIL as the columns.
GROUP_NAME GROUP_ID PASS FAIL
GROUP1 4 339 382
Pivot isn't available in Netezza so I was wondering what the best way to go about this would be. What is the best way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有使用 netezza 的直接经验,但从我读到的内容来看,它支持 SUM/CASE 的标准 SQL 解决方案
I don't have direct experience with netezza but from what I've read it supports the standard SQL solution of SUM/CASE
只需对上面的查询的修改版本进行自连接,每个查询都会生成您需要的
pass
和fail
列之一(请注意,我还没有测试过这是因为我没有安装 Netezza 来使用):Just do a self-join of modified versions of your query above, each of which produces one of the
pass
andfail
columns that you need (note that I haven't tested this since I don't have an installation of Netezza to work with):