2010-12-14 3 views
0
select min(q.rid) 
    from qvalues q 
     inner join batchinfo b 
      on q.rowid = b.rowid 
       and b.instrument = 'tf1' 
    group by q.rowid, q.name, q.compound 
    having count(*) > 1 
  1. どのように私は(RID)分を除いてすべてを削除しますか?
  2. どうすればmax(rid)以外のすべてを削除できますか?

は最大が、すべてを削除するには、私は同じROWIDを持つ値のみを削除することに注意してください名、および化合物削除行(RID)

+0

と同じことを行います[関連の質問](http://stackoverflow.com/questions/4443451/expression-of-non-boolean-type/4443497#4443497) –

答えて

0
begin transaction 

delete from [table] 
where rid != 
(select min(q.rid) 
from qvalues q 
    inner join batchinfo b 
     on q.rowid = b.rowid 
      and b.instrument = 'tf1' 
group by q.rowid, q.name, q.compound 
having count(*) > 1) 
and rowid != 
(select q.rowid 
from qvalues q 
    inner join batchinfo b 
     on q.rowid = b.rowid 
      and b.instrument = 'tf1' 
group by q.rowid, q.name, q.compound 
having count(*) > 1) 
and name != 
(select q.name 
from qvalues q 
    inner join batchinfo b 
     on q.rowid = b.rowid 
      and b.instrument = 'tf1' 
group by q.rowid, q.name, q.compound 
having count(*) > 1) 
and compound != 
(select q.compound 
from qvalues q 
    inner join batchinfo b 
     on q.rowid = b.rowid 
      and b.instrument = 'tf1' 
group by q.rowid, q.name, q.compound 
having count(*) > 1) 

してください、あなたは最大の構文

+0

@ラミーありがとう、私は同じrowidを持つ値だけを削除したいことに注意してください、名前、およびこのセットのような化合物 –

+0

updated ........ – Ramy

+0

また、私はbegin transaction aいくつかのプロダクションDBでこれを実際に使用している場合の初めからです。それがあなたの好きになったら、最後に「コミット」を使います。そうでなければ "ロールバック"を使用してください – Ramy