34,593
社区成员
发帖
与我相关
我的任务
分享
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([num] int,[name] varchar(1))
insert [tb]
select 1,'a' union all
select 1,'b' union all
select 2,'c' union all
select 2,'a' union all
select 3,'a'
go
select * from
(select distinct num from tb ) a ,
(select distinct name from tb ) b
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([num] int,[name] varchar(1))
insert [tb]
select 1,'a' union all
select 1,'b' union all
select 2,'c' union all
select 2,'a' union all
select 3,'a'
go
select *
from
(select num from tb group by num) a,
(select name from tb group by name) b
/**
num name
----------- ----
1 a
1 b
1 c
2 a
2 b
2 c
3 a
3 b
3 c
(9 行受影响)
**/