有一个order的表,字段有orderID,username,create_time。如何查询出异常用户及其异常订单?
异常用户的判定:同一用户,每一小时内下单超过十个则为异常用户
注:是每个小时的噢,一个24个小时,然后一年365天,都要查出来,只有用户有一次一小时内充值下单超过十次就算异常,要查出所有异常单和异常用户
高洛峰2017-04-17 14:55:29
You can use mysql's group by username to perform classification and aggregation, count the summary results (orderID), and limit the create_time to within 1 hour. I don't know what field you use for create_time, whether it is an unsigned integer or a date. Time type, their definition methods are different, please search by yourself.
伊谢尔伦2017-04-17 14:55:29
select *
from order AS o
where o.create_time > DATE_SUB(now(),INTERVAL 10 MINUTE)