久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

錯誤:“在包含外部引用的聚合表達式中指定了多

Error: quot;Multiple columns are specified in an aggregated expression containing an outer reference.quot;(錯誤:“在包含外部引用的聚合表達式中指定了多個列.)
本文介紹了錯誤:“在包含外部引用的聚合表達式中指定了多個列."的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在嘗試執行以下查詢時收到此錯誤.有什么想法或建議嗎?

I am receiving this error when trying to execute the query below. Any ideas or suggestions?

錯誤:

在包含外部引用的聚合表達式中指定了多個列.如果聚合的表達式包含外部引用,則該外部引用必須是表達式中唯一引用的列.

Multiple columns are specified in an aggregated expression containing an outer reference. If an expression being aggregated contains an outer reference, then that outer reference must be the only column referenced in the expression.

SELECT TestInstances.pkTestInstanceID AS 'pkTestInstanceID',
               bands.pkPerformanceLevelReportBandID AS 'BandID',
               bands.StackPosition AS 'StackPosition',
               (SELECT TOP 100 PERCENT SUM(CASE WHEN bands.StackPosition = b.StackPosition THEN 1 ELSE 0 END) * 100/ CASE WHEN COUNT(StudentScores_Subject.pkStudentScoreID) = 0 THEN 1 ELSE COUNT(StudentScores_Subject.pkStudentScoreID) END
                FROM PerformanceLevelReportBands b 
                WHERE b.fkPerformanceLevelReportID = @intPerfLevelReportId
                ORDER BY SUM(CASE WHEN bands.StackPosition = b.StackPosition THEN 1 ELSE 0 END) * 100/ CASE WHEN COUNT(StudentScores_Subject.pkStudentScoreID) = 0 THEN 1 ELSE COUNT(StudentScores_Subject.pkStudentScoreID) END) AS 'Percent',
         COUNT(StudentScores_Subject.pkStudentScoreID) AS 'Count'
         FROM StudentScores_Subject
                INNER JOIN StudentTests ON StudentScores_Subject.fkStudentTestID = StudentTests.pkStudentTestID
                INNER JOIN TestInstances ON  TestInstances.pkTestInstanceID = StudentTests.fkTestInstanceID
                INNER JOIN CAHSEE_TestPeriods ON CAHSEE_TestPeriods.pkTestPeriodID = TestInstances.fkTestPeriodID
                INNER JOIN PerformanceLevelReportBands bands ON bands.fkPerformanceLevelReportID = @intPerfLevelReportId
                LEFT JOIN MMARS_Web_TestInfo_California.dbo.PerfLevelReportBandCutScores cutScores ON cutScores.fkPerformanceLevelReportBandID = bands.pkPerformanceLevelReportBandID
                    AND cutScores.fkGradeID = @intGradeId
                    AND cutScores.fkTestSubjectID IN (SELECT id FROM @tempSubs)
                INNER JOIN PerfLevelReportBandComponents bandComponents ON bandComponents.fkPerformanceLevelReportBandID = bands.pkPerformanceLevelReportBandID 
                    AND((bandComponents.ScoreValue = StudentScores_Subject.ScoreValue) OR 
                        ((CAST(StudentScores_Subject.ScoreValue AS INT) BETWEEN bandComponents.minScore and bandComponents.maxScore)
                          OR 
                         (CAST(StudentScores_Subject.ScoreValue AS INT) BETWEEN cutScores.minScore and cutScores.maxScore)))
                RIGHT JOIN MM_SchoolYears ON MM_SchoolYears.pkSchoolYearID = TestInstances.fkSchoolYearID
        WHERE MM_SchoolYears.pkSchoolYearID IN (SELECT number FROM itot(@strYearIds, N','))
                AND StudentScores_Subject.fkStudentTestID IN (SELECT id FROM @tempTests)
                AND StudentScores_Subject.fkScoreTypeID = bandComponents.fkScoreTypeID
                AND StudentScores_Subject.fkTest_SubjectID IN (SELECT id FROM @tempSubs)
        GROUP BY TestInstances.pkTestInstanceID, bands.pkPerformanceLevelReportBandID, bands.StackPosition
        ORDER BY TestInstances.pkTestInstanceID, bands.pkPerformanceLevelReportBandID, bands.StackPosition

推薦答案

這里的問題是你不能在聚合函數中組合外部和內部引用

The problem is here you can't combine an outer and inner reference in an aggregate function

(SELECT TOP 100 PERCENT SUM(CASE WHEN bands.StackPosition = b.StackPosition THEN 1 ELSE 0 END) * 100/ CASE
                                                                                                             
WHEN COUNT(StudentScores_Subject.pkStudentScoreID) = 0 THEN 1
                                                                                                            
ELSE COUNT(StudentScores_Subject.pkStudentScoreID)
                                                                                                        
 END
   FROM PerformanceLevelReportBands b
   WHERE b.fkPerformanceLevelReportID = @intPerfLevelReportId
   ORDER BY SUM(CASE WHEN bands.StackPosition = b.StackPosition THEN 1 ELSE 0 END) * 100/ CASE
                                                                                              
WHEN COUNT(StudentScores_Subject.pkStudentScoreID) = 0 THEN 1
                                                                                              
ELSE COUNT(StudentScores_Subject.pkStudentScoreID)
                                                                                          
END) AS 'Percent'

所以改成

(SELECT TOP 100 PERCENT SUM(CASE WHEN bb.StackPosition = b.StackPosition THEN 1 ELSE 0 END) * 100/ CASE
                                                                                                            
  WHEN COUNT(StudentScores_Subject.pkStudentScoreID) = 0 THEN 1
                                                                                                            
  ELSE COUNT(StudentScores_Subject.pkStudentScoreID)
                                                                                                        
 END
   FROM PerformanceLevelReportBands b JOIN PerformanceLevelReportBands bb
    ON bb.fkPerformanceLevelReportID =bands.fkPerformanceLevelReportID 
    AND b.fkPerformanceLevelReportID =bb.fkPerformanceLevelReportID
   WHERE b.fkPerformanceLevelReportID = @intPerfLevelReportId
   ORDER BY SUM(CASE WHEN bb.StackPosition = b.StackPosition THEN 1 ELSE 0 END) * 100/ CASE
                                                                                              
 WHEN COUNT(StudentScores_Subject.pkStudentScoreID) = 0 THEN 1
                                                                                              
 ELSE COUNT(StudentScores_Subject.pkStudentScoreID)
                                                                                          
 END) AS 'Percent'

這里有更詳細的詳細解釋.

這篇關于錯誤:“在包含外部引用的聚合表達式中指定了多個列."的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 亚洲精品久久久久久宅男 | 岛国午夜 | 欧美黄在线观看 | 午夜欧美一区二区三区在线播放 | 伊人网99| 日本五月婷婷 | 风间由美一区二区三区在线观看 | 成人av色 | 日日干日日操 | 色888www视频在线观看 | 亚洲综合伊人 | 欧美一a一片一级一片 | 成人区精品 | 美日韩精品 | 久草福利 | 欧美精品久久久 | 亚洲欧美日韩久久 | 亚洲高清成人 | 中文字幕日韩三级 | 久久久一区二区三区 | 国产偷录视频叫床高潮对白 | 欧美日韩中文字幕在线播放 | 久久精品一区二区三区四区 | 国产精品国产精品国产专区不卡 | 国产精品99久久久久久人 | heyzo在线| 中文字幕在线观看 | 99欧美精品 | 色综合久久天天综合网 | 人人艹人人爽 | 一区二区三区视频在线 | 国产精品久久久久久久7电影 | 成人综合一区二区 | 欧美精品一区三区 | 免费在线a视频 | 国产丝袜人妖cd露出 | 国产精品三级 | 欧美一级淫片免费视频黄 | 亚洲一级视频在线 | 鲁一鲁资源影视 | 国产九九九九 |