select * from(
select 1 a,2 b,3 c union
select 2,3,4 union
select 3,4,5) m
order by newid()
select 1 a,2 b,3 c union
select 2,3,4 union
select 3,4,5) m
order by newid()
解决方案 »
- 跨表做乘法
- 同一问题,再开一贴
- [求助]我的sqlserver2000无法启动服务了。
- Sql Server2005输入法的问题
- 请问我要达到这样的要求该怎样写SQL 语句?当销售单中零件的供应商有指定时,则显示库存表中该零件对应的供应商的库存量;若销售单中没有
- SQLServer并行执行SQL语句问题
- llitcwl(中国龙) 请看!
- 如何把access的数据库转化为SQL SERVERR的
- 作个问卷调查,大家在sql server中数据导入导出,使用哪个工具:DTS,BCP,BULK INSERT,SELECT INTO..,还有BCP,BULK INSERT是否可在sp中使用
- 由于两部机子不联网怎么将一部机子的符合条件的数据导入到另一部机子的同一个数据表里
- 关于packet size
- 一个简单的数据库备份问题!
select * from
((select top 3 examid from tblexam
where examtype = 16 and examsubject in(1,53,56,57,58,54,59,60,61,55,62,63,64)
and examid not in (35) ) a
union
(select examid from tblexam where examid in (37) group by examid having avg(examdiff) = 1) b) m
order by newid()
go
declare @tb table (id int identity,diff int default 20)
insert @tb(diff)
select 120 union
select 10 union
select 25 union
select 37 union
select 58 union
select 47 union
select 20 union
select 246 union
select 256 union
select 12declare @tmp table(id int,diff int)
declare @avgValue int,@loop int
select @avgValue=10,@loop=1
insert @tmp select * from @tb where id in(1,2,3)while 1>0
begin
insert @tmp select top 2 * from @tb where id not in(1,2,3) order by newid()
if (select avg(diff) from @tmp)=@avgValue
break
else
delete from @tmp where id not in(1,2,3) set @loop=@loop+1
if @loop>=100
break
end if (select count(1) from @tmp)<5
print '程序循环'+convert(varchar,@loop)+'次,未找到符合条件的记录'
else
select * from @tmp
go
declare @tb table (id int identity,diff int default 20)
insert @tb(diff)
select 120 union
select 10 union
select 25 union
select 37 union
select 58 union
select 47 union
select 20 union
select 246 union
select 256 union
select 12declare @tmp table(id int,diff int)
declare @avgValue int,@loop int
select @avgValue=10,@loop=1
insert @tmp select * from @tb where id in(1,2,3)while 1>0
begin
insert @tmp select top 2 * from @tb where id not in(1,2,3) order by newid()
if (select avg(diff) from @tmp)=@avgValue
break
else
delete from @tmp where id not in(1,2,3) set @loop=@loop+1
if @loop>=100
break
end if (select count(1) from @tmp)<5
print '程序循环'+convert(varchar,@loop)+'次,未找到符合条件的记录'
else
select * from @tmp
((select top 3 examid from tblexam
where examtype = 16 and examsubject in(1,53,56,57,58,54,59,60,61,55,62,63,64)
and examid not in (35) ) a
union
(select examid from tblexam where examid in (37) group by examid having avg(examdiff) = 1) b) m
order by newid() 服务器: 消息 156,级别 15,状态 1,行 5
在关键字 'union' 附近有语法错误。
服务器: 消息 170,级别 15,状态 1,行 6
第 6 行: 'b' 附近有语法错误。