简体   繁体   English

从sum将可选值插入db列

[英]Inserting an optional value into a db column from sum

I am building a database that looks like a student grade book With four subjects, total and grade. 我正在建立一个看起来像是一个学生成绩册的数据库,其中包含四个科目,即总成绩和年级。 I created six tables in mysqli db with the following names Eng1. 我在mysqli db中创建了六个表,其名称分别为Eng1。 Eng2 eng3 engtotal enggrade. Eng2 eng3 engtotal enggrade。

I have prepared an insertion script for the first four tables, I have also written the sum code which will handle the engtotal column insertion. 我已经为前四个表准备了一个插入脚本,还编写了用于处理总列插入的求和代码。

Now I need to include the grading code which will insert (a,b,c or d) Assuming the student total score is 80 and above it will insert (a) into the enggrade column if 79 to 50 it will insert (b) etc. Below is the codes I have managed to write. 现在,我需要包含将插入(a,b,c或d)的评分代码,假设学生的总分是80,并且高于该分数,则将插入(a)到enggrade列中,如果79到50则将插入(b)等下面是我设法编写的代码。

$sql="INSERT INTO test ( fullname,
password, regno,  sclass, fcomment, ftname, nclass, eng1, eng2, eng3, eng4,
engtotal) Values( '', '".$fullname."', 
'".$password."',
'".$regno."',
'".$sclass."',
'".$fcomment."',
'".$ftname."',
'".$nclass."',
'".$eng1."',
'".$eng2."',
'".$eng3."',
 '".$eng4."', ('".$eng1+$eng2+eng3+eng4."') AS SUM);";

$query_new_user_insert = $this->db_connection->query($sql);

I have solved my problem. 我已经解决了我的问题。 I used select instead of insert my solution in below. 我使用select而不是在下面插入解决方案。

$sql = "SELECT total, field1, field2, field3, CASE WHEN total >=70 THEN 'A' WHEN total BETWEEN 69 AND 55 THEN 'B' ELSE 'C' END AS 'field4' $ sql =“ SELECT总计,字段1,字段2,字段3,当总计> = 70时,则为'A'当在69和55之间总计时,则为'B',否则为'C',结尾为'field4'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM