select * from qvalues where rowid in (
select rowid from qvalues where rowid in (select rowid from batchinfo where datapath not like '%thc%' and datapath not like '%pain%' and datapath not like 'tf1' and datapath like '%excel short%')
and (compound='etg')
and name='qc1'
group by rowid
having (COUNT(rowid)>1))
and name='qc1'
order by rowid,rid
上面的語句刪除值返回此:幫助與困難T-SQL查詢
rid name compound rt response finalConc qvalue rowid
508898 QC1 ETG 33,463.34 3,388.83 719.38 100 17800
508900 QC1 ETG 33,463.34 3,388.83 617.09 100 17800
510382 QC1 ETG 41,657.33 4,662.37 742.01 100 17860
510384 QC1 ETG 33,463.34 3,388.83 617.09 100 17860
527192 QC1 ETG 106,578.46 15,116.28 894.79 100 18478
527194 QC1 ETG 33,463.34 3,388.83 617.09 100 18478
527198 QC1 ETG 110,313.48 16,699.65 877.02 100 18479
527200 QC1 ETG 33,463.34 3,388.83 617.09 100 18479
527204 QC1 ETG 107,128.41 15,052.29 852.51 100 18480
527206 QC1 ETG 33,463.34 3,388.83 617.09 100 18480
527210 QC1 ETG 116,257.86 16,929.16 841.9 100 18481
527212 QC1 ETG 33,463.34 3,388.83 617.09 100 18481
527216 QC1 ETG 102,569.68 17,601.24 991.17 100 18482
527218 QC1 ETG 33,463.34 3,388.83 617.09 100 18482
527222 QC1 ETG 120,925.71 15,204.38 715.48 100 18483
527224 QC1 ETG 33,463.34 3,388.83 617.09 100 18483
529873 QC1 ETG 213,327.65 26,499.14 691.04 100 18576
529875 QC1 ETG 33,463.34 3,388.83 617.09 100 18576
540030 QC1 ETG 69,627.37 9,401.47 814.5 100 18987
540032 QC1 ETG 33,463.34 3,388.83 617.09 100 18987
540182 QC1 ETG 56,768.32 7,682.65 921.53 100 18993
540184 QC1 ETG 33,463.34 3,388.83 617.09 100 18993
540186 QC1 ETS 92,853.28 2,428.01 14.06 100 18994
我想只保留行具有第一獨特的ROWID,並刪除其餘部分。如何刪除第一次出現的唯一ROWID後的每條記錄?
呵呵,我從來沒有想過通過CTE從表格中刪除數值......我必須記住這一點。雖然我讀了「刪除所有其他」,暗示「從結果」。 – chezy525 2010-12-10 17:58:02