如何从多个视图创建摘要视图?
鉴于我有以下视图,其中 N=1..100
detail_view_N
Pant Quantity Fieldx ...
A 20
A 13
B 4
目前我们有汇总视图,这些视图插入到类似的表中
summary_view_N
Report_Name Plant Count
summary_view_1 A 2
summary_view_1 B 1
然后使用表来创建总体摘要,例如
summary_view_all_plants
Report_Name Plant Count
summary_view_1 A 2
summary_view_1 B 1
...
summary_view_N X Y
有没有办法创建 summary_view_all_plants 而无需必须创建每个单独的summary_view_N?我希望能够迭代报告列表并动态生成插入视图。
Given I have the following view where N=1..100
detail_view_N
Pant Quantity Fieldx ...
A 20
A 13
B 4
Currently we have summary views which insert to a table like
summary_view_N
Report_Name Plant Count
summary_view_1 A 2
summary_view_1 B 1
The table is then used to create an overall summary like
summary_view_all_plants
Report_Name Plant Count
summary_view_1 A 2
summary_view_1 B 1
...
summary_view_N X Y
Is there a way to create summary_view_all_plants without having to create each individual summary_view_N? I would like to be able to iterate though a list of reports and dynamically generate the insert views.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不 - 您必须定义视图使用的所有表和/或视图。
对视图进行分层并不是理想的做法。创始观点可能会改变,从而破坏相关的孩子。查询本身存在未针对性能进行优化的风险。
将值插入临时表意味着您必须删除现有记录或使用逻辑来相应地添加或更新。这也意味着必须定期执行此操作以保持同步。索引视图(又名物化视图)可能是一个潜在的解决方案。
No - you have to define all the tables and/or views utilized by a view.
Layering the views is not an ideal practice. A founding view can change, breaking related children. The queries themselves risk not being optimized for performance.
Inserting values into a temp table means you have to remove existing records or employ logic to add or update accordingly. It also means that this has to be performed periodically to keep in sync. An indexed view, AKA materialized view, might be a potential solution.
我不确定插入视图是什么意思。
也许您正在寻找这样的查询?
我假设您的所有摘要视图都访问同一个表
MyTable
。如果不是这种情况,您可能需要一个带有一些动态 SQL 的存储过程来生成您正在寻找的内容......I am not sure what you mean by insert view.
Perhaps a query like this is what you are looking for?
I am assuming all of your summary views are accessing the same table,
MyTable
. If this is not the case, you will likely need a stored procedure with some dynamic SQL to generate what you are looking for...找到了一个很好的解决办法。我有一个表,其中保存了我想要总结的视图的名称(detail_view_Names)。我思考每个报告名称并构建一个查询来执行每个报告的摘要。
要将新报告添加到摘要中,只需将新报告添加到detail_view_Names
Found a good solution to this. I have a table which holds the names of the views which I want to summarize (detail_view_Names). I go thought each Report Name and build a query that performs the summary of each report.
To add a new report to the summary, just add a new report to the detail_view_Names