--生长发育表growth--
create table Growth(
Growth_Id integer primary key, --发育表表单号
Growth_StuId integer, --学员id
Growth_Stature number, --身高
Growth_Sit number, --坐高
Growth_Head number, --头围
Growth_Circumference number, --胸围
Growth_Avoirdupois number, --体重
Growth_Eye number, --视力
Growth_Time date, --测量时间
Re varchar2(50) --备注
);--学生表--
stu_id integer,
stu_name varchar2(50)
--班级表--
class_id integer,
class_name varchar2(50)我想查询某一个班级里的所有学生的生长发育信息,
每个学生只显示一个记录,就是测量时间最后的一条.弄了一天还是没弄出来,用的是oracle数据库,请各位前辈帮帮忙!

解决方案 »

  1.   

    你这三个表 貌似没有任何联系 select Growth_Id , --
           Growth_StuId , --学员id
           Growth_Stature , --身高
           Growth_Sit , --坐高
           Growth_Head , --头围
           Growth_Circumference , --胸围
           Growth_Avoirdupois , --体重
           Growth_Eye , --视力
           Re,
           max(Growth_Time)  --测量时间 
    from  growth
    group by 
          Growth_Id , --
           Growth_StuId , --学员id
           Growth_Stature , --身高
           Growth_Sit , --坐高
           Growth_Head , --头围
           Growth_Circumference , --胸围
           Growth_Avoirdupois , --体重
           Growth_Eye , --视力
           Re
      

  2.   

    SELECT *
      FROM (SELECT s.*, g.*, row_number() over(PARTITION BY g.Growth_StuId ORDER BY Growth_Time DESC) rn
              FROM growth g, student s
             WHERE g.Growth_StuId = s.stu_id)
     WHERE rn = 1;
      

  3.   

    显然不对呀select *
      from (select Growth_Id, 
                   Growth_StuId, --学员id
                   Growth_Stature, --身高
                   Growth_Sit, --坐高
                   Growth_Head, --头围
                   Growth_Circumference, --胸围
                   Growth_Avoirdupois, --体重
                   Growth_Eye, --视力
                   Re,
                   Growth_Time, --测量时间
                   row_number() over(partition by Growth_StuId order by Growth_Time desc) rn --最新的测量记录为1
              from Growth)
     where rn = 1
      

  4.   


    --你学生表应该还有个班级编号字段吧
    select b.Growth_StuId,b.Growth_Stature,b.Growth_Sit,b.Growth_Head,
    b.Growth_Circumference,b.Growth_Avoirdupois,b.Growth_Eye,b.Growth_Time 
    from (select a.*,row_number() over(partition by Growth_StuId order by Growth_Time desc ) rn
    from 生长发育表 a) b,学生表 c,班级表 d
    where b.Growth_StuId=c.stu_id and c.class_id=d.class_id and b.rn=1 and class_name='某一个班级'