简体   繁体   English

在SQL Server中汇总数据的最佳做法是什么?

[英]What is the best practice for aggregating data in SQL Server?

I have a source table that is way too huge and queries take way too long for it to be usable directly for on-demand reporting. 我的源表太大,查询花费的时间太长,无法直接用于按需报告。

The charts we generate are time-based, usually the resolution is in months or days, so my first idea was to create a "Months" table and a "Days" table, and to filter / sum / count into these tables, essentially running all possible queries in advance. 我们生成的图表是基于时间的,通常的分辨率是几个月或几天,所以我的第一个想法是创建一个“月”表和一个“天”表,然后对这些表进行过滤/求和/计数,实际上是在运行提前进行所有可能的查询。

The question is how. 问题是如何。 My first idea was to write a C# console app to load all data for a month, and then somehow filter it (DataSet? DataView?) and then aggregate it (load into List<>? LinqToSQL?) and then update the Month and Day tables. 我的第一个想法是编写一个C#控制台应用程序以加载一个月的所有数据,然后以某种方式对其进行过滤(DataSet?DataView?),然后进行汇总(加载到List <>?LinqToSQL?),然后更新Month和Day。表。

Is there a better way to do this? 有一个更好的方法吗? I apologize in advance for the lack of code in this post. 对于本文中缺少代码,我预先表示歉意。 I am writing this for advice BEFORE I start coding. 在开始编码之前,我正在写这篇文章以寻求建议。

我的2美分是创建一个日历表(带有一些代理键)并使用SSIS汇总数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM