java - 通过连接和多个where子句MYSQL获取记录
问题描述
我在这两个表中有以下记录。
表-A
Question_No
1
2
3
4
5
表-B
Roll_No Question Ans_Option
1001 1 NULL // NULL means not attempted
1001 2 D
1001 3 NULL // NULL means not attempted
1002 1 C
1002 2 NULL // NULL means not attempted
当学生跳过问题时,此处“NULL”被显式插入到 Ans_Option 列中。
如何通过mysql查询显示以下结果?
Questions not attempted by roll no 1001 are : 1, 3, 4, 5
Questions not attempted by roll no 1002 are : 2, 3, 4, 5
我尝试使用以下代码但无法正常工作,如何使用多个 where 子句?
String skipped_Question="NULL";
String selectSQL = "select a.* from Table_A a NATURAL LEFT JOIN Table_B b
where b.Question IS NULL or b.Ans_Option=? and b.Roll_No=?";// Here I am doing wrong I think
preparedStatement = conn.prepareStatement(selectSQL);
preparedStatement.setString(1, skipped_Question);
preparedStatement.setString(2, Roll_No);
try{
rs = preparedStatement.executeQuery();
while(rs.next())
{
Not_Attempted_Questions= rs.getString(1);
list.add(Not_Attempted_Questions);
}
}
catch(SQLException e){ }
out.println(list);
非常感谢提前
解决方案
推荐阅读
- java - 如何使用 java 代码获取用户提交到 git-hub 的代码行?
- angular - 角度子路线未激活
- reactjs - 导入图像以在生成时做出反应
- c# - 在 c# 中,我有一个日期格式,其中月份是字符而不是数字,我该如何处理?
- php - 如何在 Wordpress 主题上创建和激活左侧边栏?
- java - 为什么 Collections.ncopies 返回一个可变集合?
- javascript - 有什么办法可以让我的函数在我的表中添加一行?
- c++ - 解析一个“。” 链式标识符列表,带有 qi::lexeme 并防止空格跳过
- javascript - 提交前的Js表单验证器不起作用
- php - Symfony Route 不工作 Apache 返回 404