0

我有 2 张桌子:

Table:skill
SkillID int(10) unsigned
Description varchar(100)

Table: question
QuestionID int(10) unsigned
SkillID int(10) unsigned
Details varchar(100)

每个技能的问题表中有很多行。我想运行一个查询,列出所有技能,并且该技能只有一个问题(不管哪个问题)。

怎么可能呢?

4

2 回答 2

1

FOR MYSQL 和 SQLSERVER

SELECT * 
FROM skill S 
INNER JOIN question Q ON S.SkillID=Q.SkillID 
INNER JOIN (
SELECT SkillID ,max(QuestionID) QuestionID
FROM question
GROUP BY SkillID)T
ON S.SkillID =T.SkillID AND Q.QuestionID=T.QuestionID

MYSQL

SELECT SkillID ,max(QuestionID) QuestionID
FROM question
GROUP BY SkillID
于 2013-06-16T10:32:46.467 回答
0

你可以试试这个:

SELECT SkillID, QuestionID -- or, whatever fields you would need
FROM question
GROUP BY SkillID
ORDER BY RAND()
于 2013-06-16T10:35:35.273 回答