我正在尝试比较数据库中不同表的2列,并且通过此代码可以正常工作,但是它为TRUE打印'1',为FALSE打印'0'。我希望它打印的是TRUE和FALSE作为单词。我知道在下面的第二个代码中,缺少TRUE和FALSE的引号,但是如果我输入它们,则会收到警告。你能帮我解决吗?我只希望显示TRUE或FALSE,而不是“ 1”和“ 0”。
SELECT s.solution_number, a.choice_answer,
case when s.solution_number = a.choice_answer then 'TRUE' else 'FALSE'
END as correct_answer
FROM solution s
INNER JOIN answers a on s.exercise_id_fk=a.exercise_id_fk;
UPDATE answers a
INNER JOIN solution s on s.exercise_id_fk=a.exercise_id_fk
set a.correct_answer = case
when s.solution_number = a.choice_answer then TRUE else FALSE END
where s.exercise_id_fk=a.exercise_id_fk;
这些是我的桌子:
CREATE TABLE solution(
exercise_id_fk INT,
solution_number INT,
FOREIGN KEY(exercise_id_fk) REFERENCES exercises(exercise_id)
);
CREATE TABLE answers(
exercise_id_fk INT,
student_id INT,
choice_answer INT,
correct_answer BOOLEAN,
FOREIGN KEY(exercise_id_fk) REFERENCES exercises(exercise_id)
);
答案 0 :(得分:1)
与人类历史上的每种编程语言一样,TRUE和FALSE分别是1和0。MySQL会将它们解释为数字,并且您不能通过某些配置将它们打印为“ TRUE”或“ FALSE”。您可以做的是:
SELECT IF(col = 1, 'TRUE', 'FALSE') AS correctAnswer
...