一个问题表:Question,包含Id,Name,TypeID.
一个答案表Answer,包含Id,quesAns,QuestionId.
TypeID来自Type表,QuestionId来自Question表.
要求:根据QuestionId出现的次数排序,并且按照TypeID分类.
查询Question的Id,Name.

解决方案 »

  1.   

    select
       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 
      

  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
      

  3.   

    select
       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
      

  4.   

    select
       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)
      

  5.   

    本帖最后由 roy_88 于 2011-09-20 16:47:58 编辑
      

  6.   

    select 
    typeid,name,Question.id,count(Question .id)
     from Question left join Answer
    on Question .id=Answer.QuestionId
    group by typeid,name,
    order by 4
      

  7.   

    请教一下,你们用的order by 1 ,2 , 3 呀的,干嘛用的呀 ?
      

  8.   

    请教一下,你们用的order by 1 ,2 , 3 呀的,干嘛用的呀 ?
    第几列
      

  9.   


    是指 select 顯示列的順序,3表示,顯示列第3列