mysql - php mysql匹配及返回值

标签 mysql sql

我的表是:

studens_exam_answers_tbl
----------------------------------------------------
exam_id | question_id | student_id  | student_answer 
----------------------------------------------------
    10       1           6              1 
    10       2           6              4
    10       3           6              3
    10       4           6              0
    10       5           6              5
    10       1           5              1
    10       2           5              2
    10       3           5              2
    10       4           5              5
    10       5           5              5

question_poll__tbl
--------------------------------------------------------------------------------
question_id | question  | option_1 |  option_2 | ....| option_5 |correct_answer
--------------------------------------------------------------------------------
    1          ....         ....       ....      ...    ....        5
    2          ....         ....       ....      ...    ....        2
    3          ....         ....       ....      ...    ....        3
    4          ....         ....       ....      ...    ....        4
    5          ....         ....       ....      ...    ....        1

我想用sql匹配学生答案和正确答案。如果学生回答正确,则“这是真的”,否则为“假”。如果 student_answer 为 0 '空'。

我该怎么做?

最佳答案

试试这个

 Select student id, (Case when student_answer=0
    then ""
    else
    when student_answer=correct_answer then "true"
    else "false"
    end ) as Result
    from studens_exam_answers_tbl inner join question_poll__tbl on studens_exam_answers_tbl.question_id.question_id =question_poll__tbl.question_id

关于mysql - php mysql匹配及返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16032671/

相关文章:

javascript - JS - 如何使用链式 promise 结束数据库连接

python - 添加的数据库记录在重新启动应用程序后被删除(heroku/SQLAlchemy)

sql - 长期 Oracle 开发人员/DBA 学习 SQL Server - 书籍推荐吗?

mysql - 日期时间查询搜索

java - 将表从 Teradata 复制到 mysql

mysql - 使 Zend\Db (zf2) 包含在子句之间

mysql - GROUP BY 子句中列的顺序确实会影响索引的使用

mysql - 子查询返回超过 1 行 MySQL

mysql - 在SQL表的列中分离大小相关数据是否更有效?

javascript - 如何使用 Jquery 在前端使用新记录验证现有记录