请教一个简单问题,谢谢
本帖最后由 hzg98 于 2013-03-22 09:52:12 编辑 原表
本局对端局向光缆容量
阿什大长屯48芯
阿什孟家48芯
阿什江南96芯
大长屯阿什48芯
孟家阿什48芯
江南阿什96芯
江南平山144芯
平山江南144芯
平山江南96芯
河南街平山24芯
要求得到
a端b端光缆容量
大长屯阿什48芯
孟家阿什48芯
江南阿什96芯
江南平山144芯
平山江南96芯
河南街平山24芯
目的就是去重,比如“大长屯-阿什 48芯”其实和“阿什-大长屯 48芯”是一个东西,要求去掉一个,谢谢!
[解决办法]
这个就是常见得排除重复行嘛
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
)
你根据你得需求改改就成
[解决办法]
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 )