日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
SQL Server 2008 MDX學(xué)習(xí)筆記之結(jié)果集Sets使用技巧

SQL Server 2008 MDX學(xué)習(xí)筆記之結(jié)果集Sets使用技巧是本文我們主要要介紹的內(nèi)容,接下來就讓我們從以下的幾個例子中區(qū)了解結(jié)果集Sets的使用技巧吧。

Sets的基本技巧

在Analysis Service中,Set代表元組(Tuples)的集合。在一個Set內(nèi)部,獨立的元組被用逗號隔開,如下:

 
 
 
 
  1. {   
  2. ([Product].[Category].[Accessories]),   
  3. ([Product].[Category].[Bikes]),   
  4. ([Product].[Category].[Clothing]),   
  5. ([Product].[Category].[Components])   

下面我們組裝一個基本的Sets

打開MDX查詢編輯器,如下:

例4-1

 
 
 
 
  1. SELECT  
  2. {  
  3. ([Date].[Calendar].[CY 2002], [Geography].[Country].[United States]),  
  4. ([Date].[Calendar].[CY 2003], [Geography].[Country].[United States]),  
  5. ([Date].[Calendar].[CY 2004], [Geography].[Country].[United States])  
  6. } ON COLUMNS,  
  7. {  
  8. ([Product].[Category].[Accessories]),  
  9. ([Product].[Category].[Bikes]),  
  10. ([Product].[Category].[Clothing]),  
  11. ([Product].[Category].[Components])  
  12. } ON ROWS  
  13. FROM [Step-by-Step]; 

我們增加一個元組([Product].[Subcategory].[Mountain Bikes]),如下:

例4-2

 
 
 
 
  1. SELECT  
  2. {  
  3. ([Date].[Calendar].[CY 2002], [Geography].[Country].[United States]),  
  4. ([Date].[Calendar].[CY 2003], [Geography].[Country].[United States]),  
  5. ([Date].[Calendar].[CY 2004], [Geography].[Country].[United States])  
  6. } ON COLUMNS,  
  7. {  
  8. ([Product].[Category].[Accessories]),  
  9. ([Product].[Category].[Bikes]),  
  10. ([Product].[Category].[Clothing]),  
  11. ([Product].[Category].[Components]),  
  12. ([Product].[Subcategory].[Mountain Bikes])  
  13. } ON ROWS  
  14. FROM [Step-by-Step];  
  15. /*  
  16. Executing the query ...  
  17. Members belong to different hierarchies in the function.  
  18. 函數(shù)中指定的兩個集具有不同的維數(shù)。  
  19. Execution complete  
  20. */ 

我們使用相同維數(shù)的用戶層次結(jié)構(gòu)[Product Categories],修改如下:

例4-3

 
 
 
 
  1. SELECT  
  2. {  
  3. ([Date].[Calendar].[CY 2002], [Geography].[Country].[United States]),  
  4. ([Date].[Calendar].[CY 2003], [Geography].[Country].[United States]),  
  5. ([Date].[Calendar].[CY 2004], [Geography].[Country].[United States])  
  6. } ON COLUMNS,  
  7. {  
  8. ([Product].[Product Categories].[Accessories]),  
  9. ([Product].[Product Categories].[Bikes]),  
  10. ([Product].[Product Categories].[Clothing]),  
  11. ([Product].[Product Categories].[Components]),  
  12. ([Product].[Product Categories].[Mountain Bikes])  
  13. } ON ROWS  
  14. FROM [Step-by-Step];  
  15. /* CY 2002 CY 2003 CY 2004  
  16. United States United States United States  
  17. Accessories $61,263.90 $151,136.35 $76,027.18  
  18. Bikes $14,716,804.14 $16,139,984.68 $7,951,335.55  
  19. Clothing $317,939.41 $495,443.62 $197,590.92  
  20. Components $2,526,542.06 $3,284,551.84 $1,137,105.72  
  21. Mountain Bikes $6,970,418.73 $5,832,626.02 $2,539,198.92  
  22. */ 

下面這個查詢有類似錯誤:

例4-4

 
 
 
 
  1. SELECT  
  2. {  
  3. ([Geography].[Country].[United States], [Date].[Calendar].[CY 2002]),  
  4. ([Date].[Calendar].[CY 2003], [Geography].[Country].[United States]),  
  5. ([Date].[Calendar].[CY 2004], [Geography].[Country].[United States])  
  6. } ON COLUMNS,  
  7. {  
  8. ([Product].[Product Categories].[Accessories]),  
  9. ([Product].[Product Categories].[Bikes]),  
  10. ([Product].[Product Categories].[Clothing]),  
  11. ([Product].[Product Categories].[Components]),  
  12. ([Product].[Product Categories].[Mountain Bikes])  
  13. } ON ROWS  
  14. FROM [Step-by-Step];  
  15. /*  
  16. Executing the query ...  
  17. Query (2, 4) Two sets specified in the function have different dimensionality.  
  18. 函數(shù)中指定的兩個集具有不同的維數(shù)。  
  19. Execution complete  
  20. */ 

正確應(yīng)為:

例4-5

 
 
 
 
  1. SELECT  
  2. {  
  3. ([Geography].[Country].[United States], [Date].[Calendar].[CY 2002]),  
  4. ([Geography].[Country].[United States], [Date].[Calendar].[CY 2003]),  
  5. ([Geography].[Country].[United States], [Date].[Calendar].[CY 2004])  
  6. } ON COLUMNS,  
  7. {  
  8. ([Product].[Product Categories].[Accessories]),  
  9. ([Product].[Product Categories].[Bikes]),  
  10. ([Product].[Product Categories].[Clothing]),  
  11. ([Product].[Product Categories].[Components]),  
  12. ([Product].[Product Categories].[Mountain Bikes])  
  13. } ON ROWS  
  14. FROM [Step-by-Step]; 

我們可以這樣改變順序,并增加一個行:

例4-6

 
 
 
 
  1. SELECT  
  2. {  
  3. ([Geography].[Country].[United States], [Date].[Calendar].[CY 2004]),  
  4. ([Geography].[Country].[United States], [Date].[Calendar].[CY 2003]),  
  5. ([Geography].[Country].[United States], [Date].[Calendar].[CY 2002])  
  6. } ON COLUMNS,  
  7. {  
  8. ([Product].[Product Categories].[Accessories]),  
  9. ([Product].[Product Categories].[Accessories]),  
  10. ([Product].[Product Categories].[Bikes]),  
  11. ([Product].[Product Categories].[Clothing]),  
  12. ([Product].[Product Categories].[Components]),  
  13. ([Product].[Product Categories].[Mountain Bikes])  
  14. } ON ROWS  
  15. FROM [Step-by-Step]; 

查詢結(jié)果如下:

 
 
 
 
  1. /* United States United States United States  
  2. CY 2004 CY 2003 CY 2002  
  3. Accessories $76,027.18 $151,136.35 $61,263.90  
  4. Accessories $76,027.18 $151,136.35 $61,263.90  
  5. Bikes $7,951,335.55 $16,139,984.68 $14,716,804.14  
  6. Clothing $197,590.92 $495,443.62 $317,939.41  
  7. Components $1,137,105.72 $3,284,551.84 $2,526,542.06  
  8. Mountain Bikes $2,539,198.92 $5,832,626.02 $6,970,418.73  
  9. */ 

多出的重復(fù)行怎么辦?我們可以使用distinct函數(shù)(http://msdn.microsoft.com/zh-cn/library/ms146033.aspx)

例4-6

 
 
 
 
  1. SELECT  
  2. {  
  3. ([Geography].[Country].[United States], [Date].[Calendar].[CY 2004]),  
  4. ([Geography].[Country].[United States], [Date].[Calendar].[CY 2003]),  
  5. ([Geography].[Country].[United States], [Date].[Calendar].[CY 2002])  
  6. } ON COLUMNS,  
  7. DISTINCT(  
  8. {  
  9. ([Product].[Product Categories].[Accessories]),  
  10. ([Product].[Product Categories].[Accessories]),  
  11. ([Product].[Product Categories].[Bikes]),  
  12. ([Product].[Product Categories].[Clothing]),  
  13. ([Product].[Product Categories].[Components]),  
  14. ([Product].[Product Categories].[Mountain Bikes])  
  15. }  
  16. ) ON ROWS  
  17. FROM [Step-by-Step];  
  18. /* United States United States United States  
  19. CY 2004 CY 2003 CY 2002  
  20. Accessories $76,027.18 $151,136.35 $61,263.90  
  21. Bikes $7,951,335.55 $16,139,984.68 $14,716,804.14  
  22. Clothing $197,590.92 $495,443.62 $317,939.41  
  23. Components $1,137,105.72 $3,284,551.84 $2,526,542.06  
  24. Mountain Bikes $2,539,198.92 $5,832,626.02 $6,970,418.73  
  25. */ 

關(guān)于SQL Server 2008 MDX學(xué)習(xí)筆記之結(jié)果集Sets使用技巧的知識就介紹到這里了,希望本次的介紹能夠?qū)δ兴斋@!

【編輯推薦】

  1. SQL Server數(shù)據(jù)庫DataRelation的應(yīng)用示例詳解
  2. SQL Server 2008 MDX應(yīng)用之檢索集合中的元組
  3. SQL Server 2005/2008中的CTE應(yīng)用之遞歸查詢
  4. SQL Server 2008數(shù)據(jù)庫學(xué)習(xí)筆記之MDX查詢示例
  5. 淺析SQL Server數(shù)據(jù)庫SSIS導(dǎo)入IIS日志的簡單步驟

新聞名稱:SQL Server 2008 MDX學(xué)習(xí)筆記之結(jié)果集Sets使用技巧
網(wǎng)頁URL:http://m.5511xx.com/article/dhsopos.html