Jump to content

SQL Problem


shadowskill

Recommended Posts

Hello good day, this is what my Database looks like and my problem is i cannot figure out what SQL Query i should use.

I have already solve the part where my evaluation would become "Done" and "Must Be Taken" and here are my Queries 

 

UPDATE `column_table` SET `Evaluation`= 'Done' WHERE  `Remarks` = 'PASSED'

UPDATE `column_table` SET `Evaluation`= 'Must be taken' WHERE `SubjectPrerequisite ` = 'None' AND `Remarks` = 'FAILED'

UPDATE `column_table` SET `Evaluation`= 'Must be taken' WHERE `SubjectPrerequisite ` = 'None' AND `Remarks` = 'No Grade'

 

The problem is my last query where it will UPDATE the database to "Cannot be taken" when the SubjectPrerequisite's Remarks = FAILED or Grade = 'No Grade'

 

column_table

______________________________________________________________________________________

SubjectName | SubjectPrerequisite |   Grade   |     Remarks      |       Evaluation

______________________________________________________________________________________

Fil 1             |     None                   |               |  No Grade        |      Must be taken

 

Eng 1           |     None                   |  90         | PASSED          |      Done

 

Eng 2           |     Eng 1                  |  74         |  FAILED           |       Must be taken

 

Eng 3           |     Eng 2                  |              |  No Grade         |      Cannot be taken

 

Fil 2             |     Fil 1                    |               |  No Grade        |      Cannot be taken

______________________________________________________________________________________

 

Please tell me if your having a hard time understanding my explanation guys. Thank you very much
Link to comment
Share on other sites

Assuming there is, try something like

 

 

UPDATE exam
LEFT JOIN exam as prereq
    ON exam.student_id = prereq.student_id
    AND prereq.subjectName = exam.SubjectPrerequisite
SET exam.Evaluation =
    CASE
    WHEN prereq.Remarks IN  ('FAILED','No Grade')
        THEN 'Cannot be taken'
    WHEN exam.Remarks = 'PASSED'
        THEN 'Done'
    ELSE 'Must be taken'
    END;
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.