search

Home  >  Q&A  >  body text

mysql - 查询每小时内的生成订单数超过十条的用户

有一个order的表,字段有orderID,username,create_time。如何查询出异常用户及其异常订单?

异常用户的判定:同一用户,每一小时内下单超过十个则为异常用户

注:是每个小时的噢,一个24个小时,然后一年365天,都要查出来,只有用户有一次一小时内充值下单超过十次就算异常,要查出所有异常单和异常用户

大家讲道理大家讲道理2865 days ago679

reply all(2)I'll reply

  • 高洛峰

    高洛峰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.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 14:55:29

    select *
    from order AS o
    where o.create_time > DATE_SUB(now(),INTERVAL 10 MINUTE)
    

    reply
    0
  • Cancelreply