Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 0.69 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. removing duplicates from mysql table but allowing up to 10
  2. SELECT
  3.     ip,
  4.     date,
  5.     count(ip) as count
  6. FROM
  7.     table
  8. WHERE
  9.     date
  10.         BETWEEN
  11.             '2012-02-03 00-00-00'
  12.         AND
  13.             '2012-02-03 23:59:59'
  14. group by
  15.     ip
  16. having
  17.     count > 10
  18.        
  19. delete t2
  20. from table t2
  21. join (
  22.     SELECT ip, date, (
  23.             select count(*) from
  24.             table t1
  25.             where t1.ip = t.ip and t1.date <= t.date and
  26.                 t1.date BETWEEN '2012-02-03 00-00-00' AND '2012-02-03 23:59:59'
  27.         ) as row
  28.     FROM table t
  29.     WHERE date BETWEEN '2012-02-03 00-00-00' AND '2012-02-03 23:59:59'
  30. ) t3 on t2.date = t3.date and t2.ip = t3.ip and t3.row > 10