select a.name,b.name from A a ,A b where a.name < b.name
解决方案 »
- SQL数据类型的如何选用,苦恼呀!!!
- 插入数据进两个关联的表?
- 請問怎樣可以看的到SQL Server 中的log
- 时间间隔计算
- 请问高手怎样编写动态生成SQLSERVER数据表?
- 在此也发一帖,http://expert.csdn.net/Expert/topic/1243/1243581.xml?temp=.9574701
- 请介绍一些学习sql server的书籍
- 怎么样使select len('今天') = 4
- 请教一条Sql语句
- 有没有这样的ORACLE产品来解决方案,关于远程数据库访问?
- 存储过程问题
- 安装sql的错误提示:Command line option syntax error. Type Command/? for Help.
drop table tbcreate table tb(name varchar(1))
insert into tb select 'a'
insert into tb select 'b'
insert into tb select 'c'
insert into tb select 'd'
select id=identity(int,1,1),* into # from(
select * from (select 'a' as name1) a ,(select name from tb)a2
union
select * from (select 'b' as name1) a ,(select name from tb)a2
union
select * from (select 'c' as name1) a ,(select name from tb)a2
union
select * from (select 'd' as name1) a ,(select name from tb)a2
)tp
where name1<>name create table #2(name1 varchar(20),name varchar(20))DECLARE cur CURSOR FOR
select name1,name from #
declare @name1 varchar(20),@name varchar(20)
OPEN cur
FETCH NEXT FROM cur into @name1,@name
insert into #2 select @name1,@name
FETCH NEXT FROM cur into @name1,@name
WHILE @@FETCH_STATUS = 0
BEGIN
if not exists(select 1 from #2 where name1+name=@name1+@name or name1+name=@name+@name1)
insert into #2 select @name1,@name
FETCH NEXT FROM cur into @name1,@name
END
CLOSE cur
DEALLOCATE curselect * from #2a b
a c
a d
b c
b d
c d我用了十分猪的方法
insert into tb select 'a'
insert into tb select 'b'
insert into tb select 'c'
insert into tb select 'd'
select a.name as a,b.name as b from tb a,tb b
where a.name<b.name order by a.name
drop table tb