MySQL: Count the distinct rows per day

前端 未结 3 1818
庸人自扰
庸人自扰 2020-12-03 03:25

I have an interesting query I need to do. I have a table with an INT column containing ip address numbers (using INET_ATON), and a timestamp<

3条回答
  •  天命终不由人
    2020-12-03 03:42

    $log_date     = date('Y-m-d H:i:s');
    $log_date     = date('Y-m-d H:i:s', strtotime($log_date.' -1 hour'));
    SELECT ipNum, COUNT(ipNum), COUNT(DISTINCT ipNum), DATE(timestamp), timestamp FROM tableName  WHERE `timestamp` > '".$log_date."' GROUP BY ipNum ORDER BY DATE(timestamp) DESC  
    

    THIS WILL GIVE YOU A RESULT LIKE

     ip                  TIME               COUNTIPS
    11.237.115.30     2018-01-27 19:13:51       1
    21.744.133.52     2018-01-27 19:14:03       1
    44.628.197.51     2018-01-27 19:48:12       14
    

提交回复
热议问题