-1
selectString = @"SELECT StudentRegistrationInformation.registrationNo,
                        StudentRegistrationInformation.firstName,
                        StudentRegistrationInformation.lastName,
                        StudentPayment.subjectName,
                        sum(StudentPayment.feeReceived) AS totalReceivedFee
                 FROM StudentRegistrationInformation
                 INNER JOIN StudentPayment 
                     ON StudentPayment.registrationNo =
                            StudentRegistrationInformation.registrationNo";

错误:

列“StudentRegistrationInformation.registrationNo”在选择列表中无效,因为它既不包含在聚合函数中,也不包含在 GROUP BY 子句中。

4

3 回答 3

2

您在查询中使用聚合函数。因此,您的查询需要知道如何对其余结果进行分组。就像在查询末尾添加以下内容一样简单:

GROUP BY StudentRegistrationInformation.registrationNo,
         StudentRegistrationInformation.firstName,
         StudentRegistrationInformation.lastName,
         StudentPayment.subjectName
于 2012-08-23T13:35:45.010 回答
0

因为您使用的是聚合函数“sum”,所以需要添加

GROUP BY StudentRegistrationInformation.registrationNo,
         StudentRegistrationInformation.firstName,
         StudentRegistrationInformation.lastName,
         StudentPayment.subjectName

到您的 SQL 字符串。

于 2012-08-23T13:37:27.317 回答
0

您必须在查询的末尾添加 GroupBy 在没有聚合函数的选择中的 clumns

SELECT StudentRegistrationInformation.registrationNo,
                                            StudentRegistrationInformation.firstName,
                                            StudentRegistrationInformation.lastName,
                                            StudentPayment.subjectName,
                                            sum(StudentPayment.feeReceived) AS        totalReceivedFee
                                       FROM StudentRegistrationInformation
                                            INNER JOIN StudentPayment ON
                                            StudentPayment.registrationNo=StudentRegistrationInformation.registrationNo

GROUP BY tudentRegistrationInformation.registrationNo,
                                            StudentRegistrationInformation.firstName,
                                            StudentRegistrationInformation.lastName,
                                            StudentPayment.subjectName
于 2012-08-23T13:35:38.107 回答