2013-08-22 1 views
0

에 따라 최소 및 최대 값을 떠나, 하나 개의 컬럼에서 중복을 제거 나는이 두 개의 열이 포함 된 테이블 : 나는 모든 중복 count 항목을 제거 할 수 있지만 두 행을 떠날 필요가MySQL은 두 번째 열

count | when 
101 | 10:11 
101 | 10:12 
102 | 10:13 
102 | 10:14 
102 | 10:15 
102 | 10:16 
103 | 10:17 
105 | 10:18 
105 | 10:19 
105 | 10:20 

을 최소 및 최대 값 when :

count | when 
101 | 10:11 
101 | 10:12 
102 | 10:13 _ removed 2 rows 
102 | 10:16 
103 | 10:17 
105 | 10:18 _ removed 1 row 
105 | 10:20 

이 때문에, 주로 통계적 목적에 사용되는 테이블의 크기를 최소화하기 위해서이다 동일한 Y 축 값은 무관 요점.

답변

1

delete 명령의 경우, MySQL은 join 구문을 지원합니다. 해당 기록을 삭제하는

이 구문을 사용하여 필터를 설정할 수 있습니다

delete t 
    from yourtable t join 
     (select count, min(when) as minwhen, max(when() as maxwhen 
      from yourtable 
      group by count 
     ) tokeep 
     on t.count = tokeep.count and (t.when > tokeep.minwhen and t.when < tokeep.maxwhen);