在 Oracle 中使用数据透视表的建议

2021-12-06 00:00:00 pivot sql oracle plsql

我需要一个报告,我应该使用数据透视表.报告将按类别分组.语句时使用 case 不好,因为类别很多.您可以将 Northwind 数据库视为示例,所有类别将是显示为列和报告将显示客户在类别中的偏好.我不知道其他解决方案,并在 Internet 中看到了 SQL Server 存储过程的示例.除了用例之外,您知道解决方案吗?

i need a report and i should use pivot table for it.Report will be group by categories .It is not good to use case when statement because there are many categories.u can think Northwind Database as sample and All Categories will be shown as Columns and Report will show customers preference among Categories.I dont know another solution and saw examples as Stored Procedures in Internet for Sql Server.Do u know a Solution except for using case when?

谢谢

推荐答案

一旦您获得 Oracle 11G,就会有一个 内置 PIVOT 功能.在此之前,您只能使用 CASE(或 DECODE)表达式.我在我的博客上有一篇关于如何自动执行此操作的文章.

Once you get Oracle 11G there is a built-in PIVOT feature. Prior to that, you are restricted to using CASE (or DECODE) expressions. I have an article on how to automate doing that on my blog.

相关文章