dongxi1680 2015-07-19 05:56
浏览 40
已采纳

通过乘法和四舍五入更新列值

i want to multiply my db column( ".$subject_column."_theory) value with 10/7( my subject total is 70, and i want to convert it to 100 for finding the grade.) also after multiplication the result must be rounded off

    $update_subject_statement4 = "UPDATE ".$track_table_name."

    SET `".$subject_column."` =IF(`".$subject_column."_theory`='ab',0,`".$subject_column."_theory`) WHERE
                                     evaluation_division="."'$eval_div' AND evaluation_config_id = ".$config_id." AND stream_index = ".$stream_index;   
                                    $additional_sum_update_query = $this->db->query($update_subject_statement4);
  • 写回答

1条回答 默认 最新

  • doz97171 2015-07-19 06:09
    关注
    $update_subject_statement4 = "UPDATE ".$track_table_name."
    
    SET `".$subject_column."` = ROUND(IF(`".$subject_column."_theory`='ab',0,`".$subject_column."_theory`) * 7 / 10) 
    WHERE
    evaluation_division="."'$eval_div' 
    AND evaluation_config_id = ".$config_id." 
    AND stream_index = ".$stream_index;   
    
    $additional_sum_update_query = $this->db->query($update_subject_statement4);
    

    1st: we multiplied your value with 7/10

    IF(".$subject_column."_theory='ab',0,".$subject_column."_theory) * 7 / 10

    2nd: we rounded it

    ROUND( IF(".$subject_column."_theory='ab',0,".$subject_column."_theory) * 7 / 10 )

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 在使用pyecharts时出现问题
  • ¥15 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计