An error was calculated using sum () in the database?

Source: Internet
Author: User
I set up two tables, table one for the project table TB_XM mainly has the project batch Xm_pcid and the project name Xm_name, table two is the project score table mainly has the project name XMPF_XM, the scoring jury, and the project rating Xmpf_small_zf. I now want to calculate the total score given by the judges, but the results obtained by using the following statements are not correct, such as the project named a project, the expert to the XMPF_SMALL_ZF column values of 0, 1, 1, but the result is 8. The score is generally 6 points higher, really do not know what is wrong. Let me see it, please!
$XMPC _id= ' 4 ';/******************************************/$query 1=mssql_query ("select * from TB_XM where xm_pcid= ' $ xmpc_id ' "), while ($myrow 1=mssql_fetch_assoc ($query 1)) {echo $myrow 1[xm_name]; $xm _name = $myrow 1[' xm_name ']; $query 2 = Mssql_query ("Select sum (XMPF_SMALL_ZF) as ZF from Tb_xmpf where xmpf_xm= ' $myrow 1[xm_name] '");//echo $query 2;echo "total score:"; while ($myrow 2=mssql_fetch_assoc ($query 2)) {echo $myrow 2[zf]; $query 3=mssql_query ("Update tb_xm set xm_zf= ' $myrow 2[ZF ] ' where xm_name= ' $myrow 1[xm_name] '); }


Reply to discussion (solution)

Not Sufficient conditions
SELECT * from TB_XM where xm_pcid= ' $xmpc _id '
The project name is obtained by batch, and the batch and project name are not one by one corresponding
A project name can be classified into different batches

Select SUM (XMPF_SMALL_ZF) as ZF from Tb_xmpf where xmpf_xm= ' $myrow 1[xm_name] '
Get a score by project name
But the batch factor was not taken into account

Mysql_fetch_assoc

  • Related Article

    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.