我正在尝试获取每个员工的待处理金额总数。以下查询工作正常:
SELECT SUM(amount)
FROM pending
WHERE MONTH < DATE_SUB(curdate() , INTERVAL 1 MONTH)
GROUP BY class
但是当我尝试将它添加为子查询时,它给了我以下错误:
1242 - 子查询返回多于 1 行
SELECT
(period_diff(date_format(now(), '%Y%m'),
date_format(MONTH, '%Y%m'))) AS months,
pending.amount,
pending.admission_numb,
pending.month,
staff.name,
staff.class, (
SELECT SUM(amount)
FROM pending
WHERE MONTH < DATE_SUB(curdate(), INTERVAL 1 MONTH)
GROUP BY class
)
FROM
pending JOIN staff
ON pending.admission_numb = staff.admission
GROUP BY admission
ORDER BY CAST( staff.class AS UNSIGNED ) , staff.class
任何帮助将不胜感激..