用一条SQL语句查询出A,B,C,D,E,五个字母中的任意三个的组合!(如ACB和ABC属于相同的结果)
来源:百度知道 编辑:UC知道 时间:2024/05/09 17:11:33
ID VALUE
1 A
2 B
3 C
4 D
5 E
急啊!
求高手帮帮我啊!!小弟在这里谢谢您啦!
应该是我这个效果
if object_id('pubs..tb') is not null
drop table tb
go
create table tb
(
ID int,
VALUE varchar(10)
)
insert into tb(ID,VALUE) values(1,'A')
insert into tb(ID,VALUE) values(2,'B')
insert into tb(ID,VALUE) values(3,'C')
insert into tb(ID,VALUE) values(4,'D')
insert into tb(ID,VALUE) values(5,'E' )
declare @sql varchar(8000)
set @sql = 'select '''
select @sql=@sql+VALUE from (select top 3 VALUE from tb order by newid())tc
select @sql=@sql+''''
exec(@sql)
drop table tb
select top 3 IDVALUE from 表名 order by newid()
问题再明白些吧
不是说1条语句么??
在ms sql server 里面可以用以下方式,如果在access或者oracle中要改变newid()为相应的产生随机数的语句
select * IDVALUE from tablename
where IDVALUE NOT IN
( select top 2 * from tablename order by newid()
);