随机数据生成 [英] Random Data Generation
问题描述
我有以下结构的桌子,
Hi,
I have a table in the following structure,
CREATE TABLE [dbo].[RateCard](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[rate] [money] NULL,
CONSTRAINT [PK_RateCard] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
insert into ratecard(name,rate)values('A',10);
insert into ratecard(name,rate)values('B',20);
insert into ratecard(name,rate)values('C',25);
insert into ratecard(name,rate)values('D',30);
insert into ratecard(name,rate)values('E',65);
insert into ratecard(name,rate)values('F',65);
insert into ratecard(name,rate)values('G',10);
insert into ratecard(name,rate)values('H',10);
insert into ratecard(name,rate)values('I',20);
insert into ratecard(name,rate)values('J',10);
insert into ratecard(name,rate)values('K',10);
insert into ratecard(name,rate)values('L',15);
insert into ratecard(name,rate)values('M',10);
insert into ratecard(name,rate)values('N',50);
select * from ratecard rate rate = 10 order by rate
当我运行上述查询时,我得到的结果如下:
1 A 10.00
7 G 10.00
8 H 10.00
10 J 10.00
11 K 10.00
13 M 10.00
当我第二次运行查询时,我需要输出为
7 G 10.00
1 A 10.00
8 H 10.00
10 J 10.00
11 K 10.00
13 M 10.00
当我第三次运行查询时,我需要输出为
7 G 10.00
1 A 10.00
10 J 10.00
8 H 10.00
11 K. 10.00
13 M 10.00
每次运行查询时,我都会得到随机结果。如何在SQL Server查询中执行此操作。
select *From ratecard where rate=10 order by rate
When I run the above query I get the result as follow as
1 A 10.00
7 G 10.00
8 H 10.00
10 J 10.00
11 K 10.00
13 M 10.00
When I run the query for the second time I need the output as
7 G 10.00
1 A 10.00
8 H 10.00
10 J 10.00
11 K 10.00
13 M 10.00
When I run the query for the Third time I need the output as
7 G 10.00
1 A 10.00
10 J 10.00
8 H 10.00
11 K 10.00
13 M 10.00
Each time I run the query I should get the random result. How to do it in SQL Server Query.
推荐答案
使用此代码。希望这是你期望的结果。
use this code. Hope this what you are expected result is.
select *,newid() as random From ratecard where rate=10 order by random
这篇关于随机数据生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!