日期:2014-05-19  浏览次数:20456 次

sql2000中一个简单的关于group by语句的问题
select   student_no,student_age
from   tb_student_temp
group   by   student_no
提示
tb_student_temp.student_age '   在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在   GROUP   BY   子句中  

是不是select后面有什么字段   group   by也要有几个字段???  
比如我要查询的结果显示很多个字段,按某一个字段分组该怎么写?

------解决方案--------------------
select student_no,student_age
from tb_student_temp
group by student_no,student_age
------解决方案--------------------
select student_no,max(student_age) student_age
from tb_student_temp
group by student_no
------解决方案--------------------
select 后面的字段列表中除了包括group by后面字段外,其余的都应该是聚合函数
------解决方案--------------------
多谢谢语句 就知道了