select student_no,student_age
from tb_student_temp
group by student_no
提示
tb_student_temp.student_age' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中 是不是select后面有什么字段 group by也要有几个字段??? 
比如我要查询的结果显示很多个字段,按某一个字段分组该怎么写?

解决方案 »

  1.   

    select student_no,student_age
    from tb_student_temp
    group by student_no,student_age
      

  2.   

    select *
    from tb_student_temp t
    where exists (select 1 from tb_student_temp where t.student_no=student_no and t.student_age>t.student_age)
      

  3.   

    select student_no,max(student_age) student_age
    from tb_student_temp
    group by student_no
      

  4.   

    select 后面的字段列表中除了包括group by后面字段外,其余的都应该是聚合函数
      

  5.   

    好像group by 一般用在当select中有类似与sum avg等函数的时候,这些函数之前的就要全部放在group by 后面。
      

  6.   

    哦 那就是说select后面有什么字段在分组后面也应该有什么字段
    除非是函数里面的字段,那分组后面就可以没有函数里面的字段????????
    是这样的么???
      

  7.   

    select 都应该是聚合函数
    group by 的字段可有可无
      

  8.   

    例子:
    select sum(student_age)
    from tb_student_temp
    group by student_no
      

  9.   

    出现在group by 后面的字段可以不出现select 列表中,但是出现在select 列表而又没有使用聚合函数,一定要出现在group by列表中