-1

errorcount在下面的 sql 查询中,所有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)
4

1 回答 1

1

只需更换

where sreh1.statusId=19

经过

where sreh1.statusId=19
and sreh1.id = sreh2.id
于 2013-04-30T18:32:49.277 回答