34,587
社区成员
发帖
与我相关
我的任务
分享
if object_id('[tb]') is not null drop table [tb]
go
create table tb (地址 varchar(20),月份 int)
insert into tb
select '地址A','1' union all
select '地址B','2' union all
select '地址C','3' union all
select '地址D','4' union all
select '地址E','5' union all
select '地址F','6'
go
select t1.地址,(t2.月份) from tb t1
cross join
(select cast (月份 as varchar(10)) as 月份 from tb ) t2
-------上面这个组合中,每月都必须出现5次,地址名随机的方案。where exists 还真比较难写