怎么查询相同的记录

weisai 2006-08-09 10:28:28
表中符合条件的只有一条记录。
但我要这条记录重复出现10行,select语句怎么写
以前写过的,现在忘了。

谢谢
...全文
139 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hellowork 2006-08-10
  • 打赏
  • 举报
回复
if object_id('tempdb..#t') is not null
drop table #t
declare @t table(id int,name varchar(10) )
insert @t
select 1,'A' union all
select 2,'B' union all
select 3,'C'

select top 10 id = identity(int,1,1) into #t from syscolumns
select a.* from @t a,#t where a.id = 2

drop table #t
fjye 2006-08-10
  • 打赏
  • 举报
回复
先写一个select,然后用union all 连接9个一样的select语句
比如
select * from tablea
union all
select * from tablea
union all
select * from tablea
union all
select * from tablea
......
jieyh 2006-08-10
  • 打赏
  • 举报
回复
create table tb(id int IDENTITY (1,1),col int);
insert into tb(col) values(1)
insert into tb(col) values(2)
insert into tb(col) values(3)
insert into tb(col) values(4);
declare @mcol int
select @mcol=3;
/* SQL2005
WITH tbcte(id,col,temp)
as
(
select id,col,1 from tb where col=@mcol
union all
select id,col,temp+1 from tbcte where temp<10
)
select id,col from tbcte
*/
--sql2000
declare @mi int
select @mi=0
create table #(id int,col int);
while @mi<10
begin
insert into #(id,col) select id,col from tb where col=@mcol
select @mi=@mi+1
end
select * from #
drop table #
drop table tb
weisai 2006-08-10
  • 打赏
  • 举报
回复
没有那么复杂吧
xyxfly 2006-08-09
  • 打赏
  • 举报
回复
declare @i int
set @i=0
while @i<10
select a from table where a=....

??? ^_^

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧