这是查询:
SELECT count(a.id) as itemCount,
concat(a.firstname, ' ', a.lastname) as name,
oi.status, a.id as adminID,
(SELECT count(a.id) as oldItemsCount
FROM bl_orderitems oi,
bl_researcher r,
tbladmins a
WHERE oi.status='Pending' AND
r.id=oi.researcherid AND
r.researchermanagerid=a.id AND
DATE(oi.regdate)=DATE_SUB(CURDATE(), INTERVAL 3 DAY))
as oldItemCount
FROM bl_orderitems oi,
bl_researcher r,
tbladmins a
WHERE oi.status in ('Pending', 'QA') AND
r.id=oi.researcherid AND
r.researchermanagerid=a.id
GROUP BY
name, adminID, oi.status;
此查询应返回如下内容:
itemCount name status adminID oldItemCount
5 John McKay Pending 20 125
15 Clown Ho QA 12 125
39 Jack Fell Pending 13 125
5 Mark Grunigen Pending 2 125
1 Kim Jun Li QA 2 125
206 Abama Oladen Pending 4 125
虽然我试图实现它返回唯一的 oldItemCount。
oldItemCount 应该是该套件的 count(a.id) " DATE(oi.regdate)=DATE_SUB(CURDATE(), INTERVAL 3 DAY))
"
如果我在子查询上尝试使用 DISTINCT,它会说Operand should contain 1 column(s)