use test
select * from sales
--自连接
select distinct t1.sales_date,t2.sales_date from sales t1 join sales t2 on t1.emp_id=t2.emp_id
select * from sales
--自连接
select distinct t1.sales_date,t2.sales_date from sales t1 join sales t2 on t1.emp_id=t2.emp_id
--转换类型(两个函数功能一样)
select cast(id as varchar(2))+'-'+cast(poductname as varchar(10))as 'connect' from product
select convert(varchar(2),id)+'-'+convert(varchar(10),poductname)as 'connect' from product
select cast(id as varchar(2))+'-'+cast(poductname as varchar(10))as 'connect' from product
select convert(varchar(2),id)+'-'+convert(varchar(10),poductname)as 'connect' from product
--三角函数
declare @degrees int
declare @radians float
select @degrees=0
select @radians=0
while(@degrees<=180)
begin
select
degrees=@degrees,
radians=str(@radians,7,5),
sine=str(sin(@radians),7,5),
cos=str(cos(@radians),7,5),
tangent=str(tan(@radians),7,5)
select @degrees=@degrees+10
select @radians=radians(convert(float,@degrees))
end
declare @degrees int
declare @radians float
select @degrees=0
select @radians=0
while(@degrees<=180)
begin
select
degrees=@degrees,
radians=str(@radians,7,5),
sine=str(sin(@radians),7,5),
cos=str(cos(@radians),7,5),
tangent=str(tan(@radians),7,5)
select @degrees=@degrees+10
select @radians=radians(convert(float,@degrees))
end
--产生4个随机数(rand产生0-1之间的随机浮点数)
declare @counter smallint
set @counter=1
while @counter<5
begin
select rand(@counter)as random_number
set nocount on
set @counter=@counter+1
set nocount off
end
declare @counter smallint
set @counter=1
while @counter<5
begin
select rand(@counter)as random_number
set nocount on
set @counter=@counter+1
set nocount off
end
/*看了此函数的使用后不禁有了一个写篇随机调用测试题算法的冲动,下面的一些代码虽写得不是很出彩,但大概功能应该还算都实现了。欢迎大家不吝赐教。*/
--实现随机测试的一种算法
/*过程详解:首先建两个表,一个用来装试题,一个用来做测试时提交的表,两表里面的列完全一样。当用户进行测验的时候,系统使用rand函数,自动地将此数据库中所有的100个测试问题随机地拷贝到实际的测验数据库中,每一个被测验者 教持有相同的测试问题,但问题的顺序支不同,当被测验者答完试题时系统自动地评分,*/
create table questions
(
intquestionid int,
vchquestiontext varchar(512)
)
create table testquestions
(
intquestionid int,
vchquestiontext varchar(512)
)
go
--this section populates the questions table
declare @intcounter int
declare @vchquestion varchar(64)
set nocount on
select @intcounter=1
while(@intcounter<=100)
begin
select @vchquestion='test question #'+convert(varchar(8),@intcounter)
insert into questions values(@intcounter,@vchquestion)
select @intcounter=@intcounter+1
end
go
--this section generates the random questions
declare @intquestionid int
set nocount on
delete from testquestions
select @intquestionid=ceiling(rand()*100)
while(select count(*)from testquestions)<100
begin
while(select count(*) from testquestions where intquestionid=@intquestionid)=1
begin
select @intquestionid=ceiling(rand()*100)
end
insert into testquestions
select * from questions
where intquestionid=@intquestionid
end
--以上代码大概完成了随机测试的核心技术,但如果要实现完全功能的话,需使用VB,VC OR .Net 代码编写。
/*过程详解:首先建两个表,一个用来装试题,一个用来做测试时提交的表,两表里面的列完全一样。当用户进行测验的时候,系统使用rand函数,自动地将此数据库中所有的100个测试问题随机地拷贝到实际的测验数据库中,每一个被测验者 教持有相同的测试问题,但问题的顺序支不同,当被测验者答完试题时系统自动地评分,*/
create table questions
(
intquestionid int,
vchquestiontext varchar(512)
)
create table testquestions
(
intquestionid int,
vchquestiontext varchar(512)
)
go
--this section populates the questions table
declare @intcounter int
declare @vchquestion varchar(64)
set nocount on
select @intcounter=1
while(@intcounter<=100)
begin
select @vchquestion='test question #'+convert(varchar(8),@intcounter)
insert into questions values(@intcounter,@vchquestion)
select @intcounter=@intcounter+1
end
go
--this section generates the random questions
declare @intquestionid int
set nocount on
delete from testquestions
select @intquestionid=ceiling(rand()*100)
while(select count(*)from testquestions)<100
begin
while(select count(*) from testquestions where intquestionid=@intquestionid)=1
begin
select @intquestionid=ceiling(rand()*100)
end
insert into testquestions
select * from questions
where intquestionid=@intquestionid
end
--以上代码大概完成了随机测试的核心技术,但如果要实现完全功能的话,需使用VB,VC OR .Net 代码编写。
转载于:https://blog.51cto.com/yofee/24513