1

我需要计算每周出现超过 10 次的车辆的数量,这些车辆只出现在“2012-07-24”和“2012-09-02”之间以及 . 我试过 :

select distinct * from anpr_in where location='a35.1.ob.1' and date(time) 
between '2012-07-24'and '2012-09-02' group by plate having count(plate)>10;

但它不会过滤仍然出现在该期间之外的汽车。

该表如下所示:

plate           location       number    time
T971JUR     A3024.7.IB.1         96     2012-05-13 18:06:17
HN52YWE     A3024.13.OB.1        94     2012-05-13 18:09:53
R179NBM     A335.6.OB.1          90     2012-05-13 18:08:55
WV07EAX     A35.1.IB.1           91     2012-05-13 18:05:09
HF02NFH     A334.14.IB.1         94     2012-05-13 18:06:43
HK11BHE     A33.5.IB.2           96     2012-05-13 18:07:52
39341       A35.1.OB.1           0      2012-05-13 18:08:09
CP61PCZ     A35.1.IB.1           96     2012-05-13 18:07:04
LM06UKN     A3024.8.IB.1         96     2012-05-13 18:06:44
3B001       A35.1.OB.1           0      2012-05-13 18:07:49
WG10YCT     A3024.13.OB.1        90     2012-05-13 18:08:04
HY60XTE     A3024.8.IB.1         93     2012-05-13 18:05:31
M397BLA     A334.14.OB.1         92     2012-05-13 18:06:57
4

1 回答 1

1

这应该返回符合您标准的板数

SELECT COUNT(*) plate_count
FROM (SELECT plate
      FROM anpr_in
      WHERE location='a35.1.ob.1'
      AND DATE(time) BETWEEN '2012-07-24' AND '2012-09-02'
      GROUP BY plate
      HAVING COUNT(*) > 10) x

SQLFIDDLE

您不需要DISTINCT,因为GROUP BY已经将其减少到不同的车牌号。

于 2013-08-28T20:36:40.043 回答