更新:
以下是我的询问:
$questionquery = "
SELECT q.QuestionId, q.QuestionContent, o.OptionType, q.NoofAnswers, GROUP_CONCAT(an.Answer ORDER BY an.Answer SEPARATOR ' ') AS Answer, r.ReplyType,
q.QuestionMarks
FROM Answer an
INNER JOIN Question q ON q.AnswerId = an.AnswerId
JOIN Reply r ON q.ReplyId = r.ReplyId
JOIN Option_Table o ON q.OptionId = o.OptionId
WHERE ".implode(" AND ", array_fill(0, $numTerms, "q.QuestionContent LIKE ?"))."
GROUP BY q.QuestionId, q.SessionId, q.QuestionContent, o.OptionType, q.NoofAnswers, Answer, r.ReplyType, q.QuestionMarks
ORDER BY ".implode(", ", array_fill(0, $numTerms, "IF(q.QuestionContent LIKE ?, 1, 0) DESC"))."
";
上述查询将提供对字符串的搜索,并在“问题”列下输出包含该字符串的行。
我有一个URL您可以访问我的应用程序,请按照以下步骤使用该应用程序:
现在您可以看到,如果您仔细阅读,则会有一些行完全重复,例如在每列中具有完全相同的内容(相同的问题,答案,标记,回复数量等等)
这是我想要摆脱的。我不希望它显示重复的行,但只是显示其中一行,因此它不会输出重复的行。我需要改变什么?
答案 0 :(得分:1)
编辑 关注您问题的更改
根据您的示例数据,它就是这个......
SELECT
`Question`,
`Answer`,
`Number of Marks`
FROM
yourQuery
GROUP BY
`Question`,
`Answer`,
`Number of Marks`
但这导致我怀疑你还没有告诉我们其他的事情吗?
答案 1 :(得分:0)
要显示不重复的行,除非我遗漏了某些内容,否则只需要添加DISTINCT子句,如下所示:
$questionquery = "
SELECT DISTINCT q.QuestionId, q.QuestionContent, o.OptionType, q.NoofAnswers,
GROUP_CONCAT(an.Answer ORDER BY an.Answer SEPARATOR ' ') AS Answer, r.ReplyType,
q.QuestionMarks
FROM Answer an
INNER JOIN Question q ON q.AnswerId = an.AnswerId
JOIN Reply r ON q.ReplyId = r.ReplyId
JOIN Option_Table o ON q.OptionId = o.OptionId
WHERE ".implode(" AND ", array_fill(0, $numTerms, "q.QuestionContent LIKE ?"))."
GROUP BY q.QuestionId, q.SessionId, q.QuestionContent, o.OptionType, q.NoofAnswers, Answer, r.ReplyType, q.QuestionMarks
ORDER BY ".implode(", ", array_fill(0, $numTerms, "IF(q.QuestionContent LIKE ?, 1, 0) DESC"))."
";
答案 2 :(得分:0)
q.SessionId和Answer分组的任何特殊原因?我希望你的结果集中有重复的行,如果你按照你没有选择的字段(q.SessionID)进行分组,并且按照答案声音分组错误,因为它是聚合函数的结果。