我正在尝试对从订单的子查询计数收到的所有订单执行求和,但我收到错误说错误代码:1242。子查询返回超过1行 < / p>
查询:
select sum((select count(orderNo) as count from order r group by r.status
having r.status in ('Open','shipped In Progress','New')));
答案 0 :(得分:1)
所以我找到了一种对我有用的方法。
select sum(a.count)
from(select count(o.order) as count from order o )a
答案 1 :(得分:-1)
只需删除GROUP BY
并使用WHERE
select sum( (select count(orderNo) as count
from order r
WHERE r.status in ('Open','shipped In Progress','New')
)
);
实际上您不需要SUM
或子查询:
SELECT count(orderNo) as count
FROM order r
WHERE r.status in ('Open','shipped In Progress','New')