需要基于其他列中的值更新表中的新列

时间:2018-11-05 20:29:25

标签: mysql

enter image description here我正在尝试根据每条记录的其他列中的值来更新新的“ rubricscore”列。也就是说,如果一列具有特定的字符串值,我将在总数中加1,如果它具有不同的值,则我将添加2。每列有3个可能性。我需要对5列进行此操作。然后,无论总值是多少,我都将使用该值更新新的“ rubricscore”列。到目前为止,我已经知道了:

SELECT id, @runtot AS rt,
CASE 
    WHEN classroommanagment = 'Self direction' THEN @runtot := @runtot + 1
    WHEN classroommanagment = 'Restating directions' THEN @runtot := @runtot + 2 
    WHEN classroommanagment = 'Moving' THEN @runtot := @runtot + 3
    WHEN teacherrole LIKE '%Mini lesson%' THEN @runtot := @runtot + 1
    WHEN teacherrole LIke '%Managing%' THEN @runtot := @runtot + 2 
    WHEN teacherrole LIKE '%Moving%' THEN @runtot := @runtot + 3
    and etc for the remaining three colomns

    END 
    FROM RUBERIC 

0 个答案:

没有答案