-- 这个意思? SQL> with t as( 2 select 'a' name from dual 3 union all 4 select 'b' from dual 5 union all 6 select 'c' from dual 7 union all 8 select 'd' from dual 9 ) 10 select t1.name Blue,t2.name Green from t t1 join t t2 on t1.name<t2.name;BL GR -- -- a b a c a d b c b d c d
--> 生成测试数据表: [tb] IF OBJECT_ID('[tb]') IS NOT NULL DROP TABLE [tb] GO CREATE TABLE [tb] ([name] [nvarchar](10)) INSERT INTO [tb] SELECT 'a' UNION ALL SELECT 'b' UNION ALL SELECT 'c' UNION ALL SELECT 'd'--SELECT * FROM [tb]-->SQL查询如下: select a.name+' VS '+b.name as nvn from tb a ,tb b where a.name<b.name /* nvn ------------------------ a VS b a VS c a VS d b VS c b VS d c VS d(6 行受影响) */受猫大侠的点醒,也猜一下
--> 测试数据:[ta] if object_id('[ta]') is not null drop table [ta] go create table [ta]([name] varchar(1)) insert [ta] select 'a' union all select 'b' union all select 'c' union all select 'd'--------------------------------查询开始------------------------------select a.name+char(32)+'vs'+char(32)+b.name from [ta] a cross join [ta] b where a.name<>b.name /* ------ a vs b a vs c a vs d b vs a b vs c b vs d c vs a c vs b c vs d d vs a d vs b d vs c(12 行受影响) */
是比赛一场呀 --> 测试数据:[ta] if object_id('[ta]') is not null drop table [ta] go create table [ta]([name] varchar(1)) insert [ta] select 'a' union all select 'b' union all select 'c' union all select 'd'--------------------------------查询开始------------------------------select a.name+char(32)+'vs'+char(32)+b.name from [ta] a , [ta] b where a.name<b.name /* ------ a vs b a vs c a vs d b vs c b vs d c vs d(6 行受影响)*/
-- 这个意思?
SQL> with t as(
2 select 'a' name from dual
3 union all
4 select 'b' from dual
5 union all
6 select 'c' from dual
7 union all
8 select 'd' from dual
9 )
10 select t1.name Blue,t2.name Green from t t1 join t t2 on t1.name<t2.name;BL GR
-- --
a b
a c
a d
b c
b d
c d
IF OBJECT_ID('[tb]') IS NOT NULL
DROP TABLE [tb]
GO
CREATE TABLE [tb] ([name] [nvarchar](10))
INSERT INTO [tb]
SELECT 'a' UNION ALL
SELECT 'b' UNION ALL
SELECT 'c' UNION ALL
SELECT 'd'--SELECT * FROM [tb]-->SQL查询如下:
select a.name+' VS '+b.name as nvn from tb a ,tb b where a.name<b.name
/*
nvn
------------------------
a VS b
a VS c
a VS d
b VS c
b VS d
c VS d(6 行受影响)
*/受猫大侠的点醒,也猜一下
if object_id('[ta]') is not null drop table [ta]
go
create table [ta]([name] varchar(1))
insert [ta]
select 'a' union all
select 'b' union all
select 'c' union all
select 'd'--------------------------------查询开始------------------------------select a.name+char(32)+'vs'+char(32)+b.name
from [ta] a cross join [ta] b
where a.name<>b.name
/*
------
a vs b
a vs c
a vs d
b vs a
b vs c
b vs d
c vs a
c vs b
c vs d
d vs a
d vs b
d vs c(12 行受影响)
*/
--> 测试数据:[ta]
if object_id('[ta]') is not null drop table [ta]
go
create table [ta]([name] varchar(1))
insert [ta]
select 'a' union all
select 'b' union all
select 'c' union all
select 'd'--------------------------------查询开始------------------------------select a.name+char(32)+'vs'+char(32)+b.name
from [ta] a , [ta] b
where a.name<b.name
/*
------
a vs b
a vs c
a vs d
b vs c
b vs d
c vs d(6 行受影响)*/