一个问题表:Question,包含Id,Name,TypeID.
一个答案表Answer,包含Id,quesAns,QuestionId.
TypeID来自Type表,QuestionId来自Question表.
要求:根据QuestionId出现的次数排序,并且按照TypeID分类.
查询Question的Id,Name.
一个答案表Answer,包含Id,quesAns,QuestionId.
TypeID来自Type表,QuestionId来自Question表.
要求:根据QuestionId出现的次数排序,并且按照TypeID分类.
查询Question的Id,Name.
a.typeid,a.name
count(b.questionid)
from
question a,answer b
where
a.id=b.questionid
group by
a.typeid,a.name
order by
2
SELECT A.ID,A.NAME,A.TYPEID,COUNT(1) COUNT FROM QUESTION A
INNER JOIN ANSWER B
ON A.ID = B.QUESTIONID
GROUP BY A.ID,A.NAME,A.TYPEID
ORDER BY COUNT DESC
a.typeid,a.name
count(b.questionid)
from
question a,answer b
where
a.id=b.questionid
group by
a.typeid,a.name
order by
3
a.id,a.typeid,a.name,count(b.questionid)
from
question a ,answer b
where
a.id=b.questionid
group by
a.id,a.typeid,a.name
order by
count(b.questionid)
typeid,name,Question.id,count(Question .id)
from Question left join Answer
on Question .id=Answer.QuestionId
group by typeid,name,
order by 4
第几列
是指 select 顯示列的順序,3表示,顯示列第3列