sql报错“选择列表中的列 'sc.CNO' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中”

 

使用Group By子句的时候,一定要记住下面的一些规则:

(1)不能Group By非标量基元类型的列,如不能Group By text,image或bit类型的列;

(2)Select指定的每一列都应该出现在Group By子句中,除非对这一列使用了聚合函数;

(3)不能Group By在表中不存在的列;

(4)进行分组前可以使用Where子句消除不满足条件的行;

(5)使用Group By子句返回的组没有特定的顺序,可以使用Order By子句指定次序。

展开阅读全文

选择列表中的列“employee.Name”无效因为没有含在聚合函数GROUP BY子句中

01-20

[code=SQL]rnSELECT rn employee.Name,employee.mainSalary, employee_salary.salaryID,section.section_name, employee_salary.overtime, rn employee_salary.phoGrants, employee_salary.bonus,rn employee_salary.houseGrants,rn employee_salary.fine, employee_salary.workClothes, employee_salary.PLX, rn employee_salary.borrower, employee_salary.rent, employee_salary.catering,rn employee_salary.Months, rn YangL,ShiY,YiL,GS,ShengY,rn attendance.attendanceDay,rn (mainSalary - ((mainSalary / (Days - holidays)) * LeaveDay) + ((mainSalary / (Days - holidays)) * (MinersDate * 2))) as AttendancePay, --出勤工资rn ((mainSalary / (Days - holidays)) * LeaveDay) as Leave, --请假扣款rn ((mainSalary / (Days - holidays)) * (MinersDate * 2)) as Miners, --矿工扣款rn ((mainSalary - ((mainSalary / (Days - holidays)) * LeaveDay) + ((mainSalary / (Days - holidays)) * (MinersDate * 2))) + overtime + phoGrants + bonus + houseGrants) as YingFaGongZi, --应发工资rn ((mainSalary - ((mainSalary / (Days - holidays)) * LeaveDay) + ((mainSalary / (Days - holidays)) * (MinersDate * 2))) + overtime + phoGrants + bonus + houseGrants)rn - (fine + workClothes + PLX + borrower + rent + catering + YangL + ShiY + YiL + GS + ShengY ) as RealWages, --实发工资rn sum(((mainSalary - ((mainSalary / (Days - holidays)) * LeaveDay) + ((mainSalary / (Days - holidays)) * (MinersDate * 2))) + overtime + phoGrants + bonus + houseGrants)rn - (fine + workClothes + PLX + borrower + rent + catering + YangL + ShiY + YiL + GS + ShengY )) as sums --合计rn FROM employee_salary INNER JOINrn employee ON employee_salary.employeeID = employee.employeeID INNER JOINrn attendance ON rn employee_salary.attendanceID = attendance.attendanceID INNER JOINrn section ON employee.sectionID = section.section_id where isLeave = 'false'and employee_salary.Months = @Months order by section.section_idrnrn[/code] 论坛

没有更多推荐了,返回首页