实验9-10 编写一个存储过程proc_test_stat3

在TestDB数据库中,编写一个存储过程proc_test_stat2,要求:

1)无参数

2)在数据库中有表exercisebook, 用于保存用户的作业,包含下列字段

exerid  作业的唯一编号;

quesid 问题编号

userid 用户编号

eval  验证结果:start,success,error

posttime 提交时间

其中,数据的语义是

a)用户和问题是多对多关系,一个用户在答题过程中对同一个问题会产生多条记录;

b)验证结果中的start表示开始实验,success表示成功结束实验,error表示验证错误;

扫描二维码关注公众号,回复: 2226873 查看本文章

c)每个用户开始实验时会在exercisebook表中增加一条eval 内容是start的记录,其中包含开始时间;

d)开始实验后,每次提交都会在exercisebook表中增加一条记录,如果验证成功则eval 是success,若错误则eval 是error

 

请以结果集返回用户的作业最近一次的提交情况,包含下列字段:

exerid, userid,quesid,eval,posttime

 

create procedure proc_test_stat2
as
begin
set nocount on;
	select exerid,userid,quesid,eval,posttime=convert(varchar(100),posttime,21)
from exercisebook a
where a.posttime in
(
    select max(b.posttime) 
    from  exercisebook b
    where a.userid=b.userid
    group by b.userid
) 
	
set nocount off
end

  

猜你喜欢

转载自www.cnblogs.com/masterchd/p/9330988.html