这个就是常见得排除重复行嘛 use tempdb go declare @tb table(id int identity(1,1),col1 varchar(10)) insert into @tb (col1) select 'A' union all select 'A' union all select 'B' union all select 'B' union all select 'B' union all select 'C' select * from @tb where id in ( select max(id) from @tb group by col1 ) 你根据你得需求改改就成
用临时表呗 select a ,b,c into #aa from table再用if条件判断a='' and b=''是否已经存在 不存在的话再执行下面的插入语句 select b,a,c into ##aa from table;
create table t_t (seqno int,fa varchar(20),fb varchar(20),fc varchar(20) ) insert into t_t values(1,'阿什','大长屯','48芯') insert into t_t values(2,'阿什','孟家','48芯') insert into t_t values(3,'阿什','江南','96芯') insert into t_t values(4,'大长屯','阿什','48芯') insert into t_t values(5,'孟家','阿什','48芯') insert into t_t values(6,'江南','阿什','96芯') insert into t_t values(7,'江南','平山','144芯') insert into t_t values(8,'平山','江南','144芯') insert into t_t values(9,'平山','江南','96芯') insert into t_t values(10,'河南街','平山','24芯')select * from t_t a where not exists( select 1 from t_t b where ( (a.fb=b.fa and a.fc=b.fc ) or (a.fa=b.fb and a.fc=b.fc) ) and a.seqno<b.seqno )
use tempdb
go
declare @tb table(id int identity(1,1),col1 varchar(10))
insert into @tb (col1)
select 'A' union all
select 'A' union all
select 'B' union all
select 'B' union all
select 'B' union all
select 'C' select * from @tb
where id in
(
select max(id) from @tb
group by col1
)
你根据你得需求改改就成
他这个表好像ID都没有,另外需要是这样的
比如“大长屯-阿什 48芯”其实和“阿什-大长屯 48芯”是一个东西,
A字段要和B字段比较
也就是说
光缆容量=我的col1
本局+对端局向=我的 ID
改动不大吧?
不存在的话再执行下面的插入语句
select b,a,c into ##aa from table;
insert into t_t values(1,'阿什','大长屯','48芯')
insert into t_t values(2,'阿什','孟家','48芯')
insert into t_t values(3,'阿什','江南','96芯')
insert into t_t values(4,'大长屯','阿什','48芯')
insert into t_t values(5,'孟家','阿什','48芯')
insert into t_t values(6,'江南','阿什','96芯')
insert into t_t values(7,'江南','平山','144芯')
insert into t_t values(8,'平山','江南','144芯')
insert into t_t values(9,'平山','江南','96芯')
insert into t_t values(10,'河南街','平山','24芯')select * from t_t a where not exists( select 1 from t_t b where
( (a.fb=b.fa and a.fc=b.fc ) or (a.fa=b.fb and a.fc=b.fc) ) and a.seqno<b.seqno )