I'm trying to compare 2 columns (difficulty, difficulty_student)
of 2 different tables (EXERCISES, ANSWERS) from the Mysql database and create a new column in the table ANSWERS comparing both tables with a VARCHAR data type (YES or NO). If the user has changed the difficulty of the exercise, a ' YES ' should appear in the cell, if it has not been changed, the cell will be ' NO '.
I would like to compare the column ' difficulty
' of the table EXERCISES and ' difficulty_student
' of the table ANSWERS , and store it in ' difficulty_change
' of the ANSWERS table. But the problem is that the column ' dificulty_change
' can not compare values until the user press the ' submit
' button, which is when they enter the value YES or NO in the column ' difficulty_student
' and thus be able to compare it with ' difficulty
' of the table EXERCISES .
These are my 2 tables.
CREATE TABLE exercises (
exercise_id INT,
difficulty INT
PRIMARY KEY(exercise_id)
);
CREATE TABLE answers(
exercise_id_fk INT,
student_id INT,
difficulty_change VARCHAR(3),
difficulty_student INT,
choice_answer INT,
FOREIGN KEY(exercise_id_fk) REFERENCES exercises(exercise_id)
);
This is what I have tried so far but I do not know which table is saving ' difficulty_change
'. I would like to save it in the ANSWERS table. Can you help me?
SELECT e.difficulty, a.difficulty_student,
case when e.difficulty = a.difficulty_student then 'NO' else 'YES'
END as difficulty_change
FROM exercises e
INNER JOIN answers a on e.exercise_id=a.exercise_id_fk;
Here is an example of how I would like the tables to remain:
I am trying to make a program in which the user has a series of exercises, and each of them has a drop-down of options where the level of difficulty of the exercise appears. By default, the pulldown of each exercise has its assigned difficulty level, but the user can change it if it seems wrong. In this way, change it or not, your answer will be saved in the table of the database.
What I would like to do is compare 2 columns% co_of% from 2 different tables (EXERCISES, ANSWERS) and create a new column in the table ANSWERS by comparing both tables by VARCHAR or BOOLEAN (YES or NO). If the user has changed the difficulty of the exercise, the cell will be 'YES', if he has not changed it, the cell will be 'NO'.
This is what my table looks like right now: