errorcount
显示所有Id
的相同值。我想要一个与sreh2.Id
对应的行特定错误数,而不是sreh1.statusId=19
的总数
我得到的结果是(到处都是错误计数列109240): -
Id hubcount errorcount
BC03262583 5 109240
BC03272635 6 109240
BC03281827 4 109240
使用此查询:
select
sreh2.Id,
count(h.hubId) as hubcount,
(select count(sreh1.statusId)
from `shipmentRouteEventHistory` sreh1
where sreh1.statusId=19
) as errorcount
FROM `shipmentRouteEventHistory` sreh2
join `hub` h on sreh2.hubId = h.hubId
WHERE sreh2.statusId=3
GROUP BY sre.Id
HAVING (count(h.hubId)>2)
答案 0 :(得分:1)
只需替换
where sreh1.statusId=19
通过
where sreh1.statusId=19
and sreh1.id = sreh2.id