程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> 一步一步學習sqlserver BI--應用開發

一步一步學習sqlserver BI--應用開發

編輯:關於SqlServer

接著我們上次那篇《一步一步學習sqlserverBi--多維數據庫建立》,現在我們多維數據庫已經有了 ,並且裡面也已經有了數據,那麼趕快進入咱們程序員的主題吧。

今天我要在這個多維數據庫上 面開發兩個應用:

1。按天統計各個部門的交易量

2。按天統計各個部門和各個游戲的交 易量

首先設計強類型的數據集,如下圖。

按部門統計數據集

按部門和游戲交叉統 計數據集

設計MDX語句,在數據層執行MDX,並返回CellSet

/**//// <summary>

/// 按天統計各個部門的交易數據
/// </summary>
/// <param name="tradeDateKey">日期的鍵值</param>
/// <returns></returns>
public CellSet Count(int tradeDateKey)
{
StringBuilder mdxBuilder = new StringBuilder();
mdxBuilder.Append("WITH MEMBER [Measures].[Total Orders Count] AS 'SUM([Measures].[Total Orders] )' ");
mdxBuilder.Append(" MEMBER [Measures].[Total Amount Count] AS 'SUM([Measures]. [Total Amount])'");
mdxBuilder.Append(" MEMBER [Measures].[Total Money Count] AS 'SUM([Measures].[Total Money])'");
mdxBuilder.Append(" MEMBER [Measures].[Un Paid Cancel Amount Count] AS 'SUM([Measures].[Un Paid Cancel Amount])'");
mdxBuilder.Append(" MEMBER [Measures].[Un Paid Cancel Money Count] AS 'SUM([Measures].[Un Paid Cancel Money])'");
mdxBuilder.Append (" MEMBER [Measures].[Paid Cancel Amount Count] AS 'SUM([Measures].[Paid Cancel Amount])'");
mdxBuilder.Append(" MEMBER [Measures].[Paid Cancel Money Count] AS'SUM([Measures].[Paid Cancel Money])'");
mdxBuilder.Append (" SELECT { [Measures].[Total Orders Count], [Measures].[Total Amount Count], [Measures].[Total Money Count], [Measures].[Un Paid Cancel Amount Count], [Measures].[Un Paid Cancel Money Count], [Measures].[Paid Cancel Amount Count], [Measures].[Paid Cancel Money Count]} ON COLUMNS,");
mdxBuilder.Append(" {[Department].[Dep Code Alternate Key].Members} ON ROWS");
mdxBuilder.Append(" FROM [Data Center DW]");
mdxBuilder.Append(" WHERE ([Time].[TimeKey]. ["+tradeDateKey+"])");

return DBServer.AnalysisServer.ExecuteCellset(mdxBuilder.ToString());
}

/**//// <summary>

/// 按天統計各個游戲單個部門的交易數據
/// </summary>
/// <param name="tradeDateKey">日期的鍵值 </param>
/// <returns></returns>
public CellSet Count(int tradeDateKey,int departmentKey)
{
StringBuilder mdxBuilder = new StringBuilder ();
mdxBuilder.Append("WITH MEMBER [Measures].[Total Orders Count] AS 'SUM ([Measures].[Total Orders] )' ");
mdxBuilder.Append(" MEMBER [Measures].[Total Amount Count] AS 'SUM([Measures].[Total Amount])'");
mdxBuilder.Append(" MEMBER [Measures].[Total Money Count] AS 'SUM([Measures]. [Total Money])'");
mdxBuilder.Append(" MEMBER [Measures].[Un Paid Cancel Amount Count] AS 'SUM([Measures].[Un Paid Cancel Amount])'");
mdxBuilder.Append(" MEMBER [Measures].[Un Paid Cancel Money Count] AS 'SUM ([Measures].[Un Paid Cancel Money])'");
mdxBuilder.Append(" MEMBER [Measures].[Paid Cancel Amount Count] AS 'SUM([Measures].[Paid Cancel Amount]) '");
mdxBuilder.Append(" MEMBER [Measures].[Paid Cancel Money Count] AS'SUM([Measures].[Paid Cancel Money])'");
mdxBuilder.Append(" SELECT { [Measures].[Total Orders Count], [Measures].[Total Amount Count], [Measures]. [Total Money Count], [Measures].[Un Paid Cancel Amount Count], [Measures].[Un Paid Cancel Money Count], [Measures].[Paid Cancel Amount Count], [Measures].[Paid Cancel Money Count]} ON COLUMNS,");
mdxBuilder.Append(" {[Game].[Game Code Alternate Key].Members} ON ROWS");
mdxBuilder.Append(" FROM [Data Center DW] ");
mdxBuilder.Append(" WHERE ([Time].[TimeKey].[" + tradeDateKey + "],[Department].[Dim Department].["+departmentKey.ToString()+"])");

return DBServer.AnalysisServer.ExecuteCellset(mdxBuilder.ToString());
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved