SQL Programming: Statistics N test scores

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.