Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在mysql中获得所有未回答的问题_Mysql - Fatal编程技术网

如何在mysql中获得所有未回答的问题

如何在mysql中获得所有未回答的问题,mysql,Mysql,我有两张桌子,回答和提问。所有问题都插入问题BL中,答案也插入问题BL中。现在,我想通过参考答案BL来获得尚未被任何人回答的问题。这是我的疑问: "SELECT * FROM questionstbl LEFT JOIN answerstbl ON answerstbl.qu_id=questionstbl.qu_id GROUP BY ans_id" 然而,结果是有答案的问题 有人知道吗?类似这样的事情: SELECT * FROM questionstbl WHERE qu_id

我有两张桌子,回答和提问。所有问题都插入问题BL中,答案也插入问题BL中。现在,我想通过参考答案BL来获得尚未被任何人回答的问题。这是我的疑问:

 "SELECT * FROM questionstbl LEFT JOIN answerstbl ON answerstbl.qu_id=questionstbl.qu_id 
  GROUP BY ans_id"
然而,结果是有答案的问题

有人知道吗?

类似这样的事情:

SELECT * FROM questionstbl WHERE qu_id NOT IN (SELECT qu_id FROM answerstbl)
大概是这样的:

SELECT * FROM questionstbl WHERE qu_id NOT IN (SELECT qu_id FROM answerstbl)

您可以在比较运算符中使用
NOT

查询

Select * from questionstbl  
where qu_id not in(
    select distinct qu_id from answerstbl
);
select
questionstbl.qu_id as questionId,
answerstbl.ans_id as answersId,
from questionstbl, answerstbl
LEFT JOIN answerstbl ON answerstbl.qu_id=questionstbl.qu_id 
where (condition to check questions that are NOT YET answered)
GROUP BY ans_id;

您可以在比较运算符中使用
NOT

查询

Select * from questionstbl  
where qu_id not in(
    select distinct qu_id from answerstbl
);
select
questionstbl.qu_id as questionId,
answerstbl.ans_id as answersId,
from questionstbl, answerstbl
LEFT JOIN answerstbl ON answerstbl.qu_id=questionstbl.qu_id 
where (condition to check questions that are NOT YET answered)
GROUP BY ans_id;

因此,您希望所有问题的答案表中不存在该问题id

SELECT Q.*
FROM questionstbl Q
WHERE NOT EXISTS(SELECT 1 FROM answerstbl A WHERE A.qu_id = Q.qu_id )
或者像这样

SELECT Q.*
FROM questionstbl Q
WHERE 
  Q.qu_id NOT IN (SELECT qu_id FROM answertbl)

因此,您希望所有问题的答案表中不存在该问题id

SELECT Q.*
FROM questionstbl Q
WHERE NOT EXISTS(SELECT 1 FROM answerstbl A WHERE A.qu_id = Q.qu_id )
或者像这样

SELECT Q.*
FROM questionstbl Q
WHERE 
  Q.qu_id NOT IN (SELECT qu_id FROM answertbl)
另一个选择是:

Select questions.qu_id, questions.question from questions INNER JOIN answers where questions.qu_id <> answers.qu_id
选择questions.qu\u id,questions.question from questions internal JOIN answers where questions.qu\u id answers.qu\u id
上面的查询结果是尚未回答的问题表中的所有问题。但是,您的查询中有一个错误,您希望得到没有答案的问题,并且您正在根据答案id对它们进行分组(这些问题的答案id不存在)。

另一个选项可以是:

Select questions.qu_id, questions.question from questions INNER JOIN answers where questions.qu_id <> answers.qu_id
选择questions.qu\u id,questions.question from questions internal JOIN answers where questions.qu\u id answers.qu\u id

上面的查询结果是尚未回答的问题表中的所有问题。但是,您的查询中有一个错误,您希望得到没有答案的问题,并且您正在根据答案id对这些问题进行分组(这些问题不存在答案id)。

应根据表中的字段输入要检查的条件,如果可以指定表字段,则可以填写条件

查询

Select * from questionstbl  
where qu_id not in(
    select distinct qu_id from answerstbl
);
select
questionstbl.qu_id as questionId,
answerstbl.ans_id as answersId,
from questionstbl, answerstbl
LEFT JOIN answerstbl ON answerstbl.qu_id=questionstbl.qu_id 
where (condition to check questions that are NOT YET answered)
GROUP BY ans_id;

应根据表中的字段输入要检查的条件,如果可以指定表字段,则可以填写条件

查询

Select * from questionstbl  
where qu_id not in(
    select distinct qu_id from answerstbl
);
select
questionstbl.qu_id as questionId,
answerstbl.ans_id as answersId,
from questionstbl, answerstbl
LEFT JOIN answerstbl ON answerstbl.qu_id=questionstbl.qu_id 
where (condition to check questions that are NOT YET answered)
GROUP BY ans_id;
看一看,看一看