mysql查询显示错误:#1241-操作数应包含1列

kcrjzv8t  于 2021-06-24  发布在  Mysql
关注(0)|答案(2)|浏览(358)

mysql查询,

SELECT qcat.name,
COUNT( CASE WHEN qas.state = "todo" THEN 1 END ) AS gtotal,
COUNT( CASE WHEN qas.state = "gradedright" THEN 1 END ) AS rightanswer, 
COUNT( CASE WHEN qas.state = "gradedwrong" THEN 1 END ) AS wronganswer, 
SUM(qas.fraction) AS grade,
quiza.id 
FROM mdl_quiz_attempts quiza
JOIN mdl_question_attempts qa ON qa.questionusageid = quiza.uniqueid 
JOIN mdl_question_attempt_steps qas ON qas.questionattemptid = qa.id 
JOIN mdl_question qstn ON ( qa.`questionid` = qstn.id ) 
JOIN mdl_question_categories qcat ON ( qstn.`category` = qcat.id ) 
WHERE quiza.id=1173 and FIND_IN_SET(qstn.id, (1,2,3,4,5,6)) GROUP BY quiza.id,qcat.name

显示错误:#1241-操作数应包含1列

mlmc2os5

mlmc2os51#

SELECT qcat.name,
COUNT( CASE WHEN qas.state = "todo" THEN 1 END ) AS gtotal,
COUNT( CASE WHEN qas.state = "gradedright" THEN 1 END ) AS rightanswer, 
COUNT( CASE WHEN qas.state = "gradedwrong" THEN 1 END ) AS wronganswer, 
SUM(qas.fraction) AS grade,
quiza.id 
FROM mdl_quiz_attempts quiza
JOIN mdl_question_attempts qa ON qa.questionusageid = quiza.uniqueid 
JOIN mdl_question_attempt_steps qas ON qas.questionattemptid = qa.id 
JOIN mdl_question qstn ON ( qa.`questionid` = qstn.id ) 
JOIN mdl_question_categories qcat ON ( qstn.`category` = qcat.id ) 
WHERE quiza.id=1173 and FIND_IN_SET(qstn.id, "1,2,3,4,5,6") GROUP BY quiza.id,qcat.name
um6iljoc

um6iljoc2#

这是错误的:

FIND_IN_SET(qstn.id, (1,2,3,4,5,6))

应该是:

qstn.id IN (1,2,3,4,5,6)

或:

qstn.id BETWEEN 1 AND 6
``` `FIND_IN_SET()` 当值列表位于逗号分隔的字符串中时使用, `IN` 与查询中的文本列表一起使用。

相关问题