当我运行以下SQL语句时:
SELECT
FORMAT(emp_attendance.att_date, 'mm-yyyy') AS pd ,
emp_detail.ename ,
emp_detail.ecode ,
( SELECT COUNT(emp_attendance.att_id)
FROM emp_attendance
WHERE emp_attendance.eid = emp_detail.eid
AND emp_attendance.att_type = 'Full Day'
AND FORMAT(emp_attendance.att_date, 'mm-yyyy') = FORMAT(emp_attendance.att_date,
'mm-yyyy')
) AS Present_Days ,
( SELECT COUNT(emp_attendance.att_id)
FROM emp_attendance
WHERE emp_attendance.eid = emp_detail.eid
AND emp_attendance.att_type = 'Half Day'
AND FORMAT(emp_attendance.att_date, 'mm-yyyy') = FORMAT(emp_attendance.att_date,
'mm-yyyy')
) AS Half_Days ,
ROUND(( emp_detail.esalary / 30 )
* ( ( SELECT COUNT(emp_attendance.att_id)
FROM emp_attendance
WHERE emp_attendance.eid = emp_detail.eid
AND emp_attendance.att_type = 'Full Day'
AND FORMAT(emp_attendance.att_date, 'mm-yyyy') = FORMAT(emp_attendance.att_date,
'mm-yyyy')
)
+ ( ( SELECT COUNT(emp_attendance.att_id)
FROM emp_attendance
WHERE emp_attendance.eid = emp_detail.eid
AND emp_attendance.att_type = 'Half Day'
AND FORMAT(emp_attendance.att_date, 'mm-yyyy') = FORMAT(emp_attendance.att_date,
'mm-yyyy')
) / 2 ) ), 2) AS Eligable_Salary
FROM
emp_attendance
INNER JOIN emp_detail ON emp_attendance.eid = emp_detail.eid
GROUP BY
FORMAT(emp_attendance.att_date, 'mm-yyyy') ,
emp_detail.eid ,
emp_detail.ename ,
emp_detail.ecode ,
Eligable_Salary
HAVING
FORMAT(emp_attendance.att_date, 'mm-yyyy') = '11-2016'
...我收到以下错误:
您尝试执行不包含指定的查询 表达式' ROUND(emp_detail.esalary / 30 *(+ / 2),2)'作为一部分 聚合函数。
答案 0 :(得分:0)
而不是GROUP BY子句中的Eligable_Salary,你应该使用emp_detail.esalary