Recently to help schools do a score input system, which has the following task requirements
Requirements Description:
There are three sheets:
1, according to the course ID can be found in the WEB_INPUTCJ_CJB table for all students of the course
2, according to the course ID can be found in the course from the WEB_INPUTCJ_XSKSB of the corresponding n-test, which have KSID (exam ID), the proportion of the score and other information
3, according to the test ID can be found in the WEB_INPUTCJ_XSCJB of each test of all the students information, (XH), CJ (the test results))
Task:
Based on this information, the total score for each test is statistically 0~100 and updated to the CJ field in WEB_INPUTCJ_CJ.
Solve:
1, the first need to be students of the comprehensive results of statistics, which is also the most critical
?
| 1 2 3 4 5 6 7 8 9 |
Select Zzcj.cj,zzcj.xh from (select Xh to WEB_INPUTCJ_CJB where kcid= @kcid) xsxx left join (select Xh,round (SUM (cjbl*0.01 *isnull (cj,0)), 0 CJ from WEB_INPUTCJ_XSCJB XSCJB left join (select KSID,CJBL from WEB_INPUTCJ_XSKSB where kcid= @kcid) ksx X on Xscjb.ksid=ksxx.ksid Group by XH) ZZCJ on Zzcj.xh=xsxx.xh |
2, with this "Final exam results form", the following is to update all of the data to the target table, here I use the cursor to implement, the complete SQL statement is as follows:
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 The 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
use [NEW_WZJW] go/****** object: storedprocedure [dbo]. [Performance Management _ Process performance Input _ Statistical final results] Script date:2014/4/1 19:22:01 ******/SET ansi_nulls on Go Set QUOTED_IDENTIFIER On Go ALTER proc [dbo]. [Performance Management _ Process performance Input _ Statistical final results] @kcid Jxrw_code as begin Declare C1 cursor for Select Zzcj.cj,zzcj.xh from (select XH From WEB_INPUTCJ_CJB where kcid= @kcid) xsxx left join (select Xh,round (SUM (cjbl*0.01*isnull (cj,0)), 0) CJ from WEB_INPUTCJ _XSCJB XSCJB LEFT Join (select KSID,CJBL from WEB_INPUTCJ_XSKSB where kcid= @kcid) ksxx on Xscjb.ksid=ks Xx.ksid GROUP by XH) ZZCJ on zzcj.xh=xsxx.xh DECLARE @cj float declare @xh varchar (a) open C1 FETCH C1 into @cj, @xh while @ @FETCH_STATUS = 0 BEGIN update WEB_INPUTCJ_CJB set cj= @cj where xh= @xh and kcid= @kcId Fetch C1 into @cj, @xh end End |