select * into #water from dbo.table1 where clo_name='理化'
--創建臨時表,並保存數據
select * from ClientMatch where method in
(select method from ClientMath group by method
having COUNT(*)>1)
order by method;
--查詢出method相同的數據
select * from ClientMath where method in
(select method from ClientMatch group by method
having COUNT(*)>1)
and
testcode in (select testcode from ClientMath group by testconde
having COUNT(*)>1)
--查詢method和testcode都重復的數據
delete from ClientMacth where
method in (select method from
ClientMatch group by method
having COUNT(*)>1)
and
testcode in (select testcode
from ClientMatch group by testcode
having COUNT(*)>1)
and
ClientMatch.ID not in (select min(ClientMatch.ID) from
ClientMatch group by testcode, method
having COUNT(*)>1)
----刪除method和testcode都重復列。可以添加一個ID自增長字段
insert into test_methods
(methodcategory,description,method,methodrptname,iscma)
select methodcategory,description,method,methodrptname,iscma from
testcode where testcode.method not in (select method from test_methods)
----講一個表中的部分數據插入到另一個表中,method為主鍵