select t.by_examine_person,
       avg(t.self_score),
       avg(t.profes_score),
       t.examine_year
  from examtrade t
 where t.examine_year = '2005'
 group by t.by_examine_person, t.examine_year;

解决方案 »

  1.   

    select by_examine_person,sum(self_score)/count(distinct examine_person),sum(profes_score)/count(distinct examine_person),
    examine_year from examtrade group by by_examine_person,examine_year
      

  2.   

    ncwuhh(天涯)  lynx(lynx)多谢你们的回答。不知两位对hibernate有没有了解。这样的sql要转换成hql应如何做呢。
      

  3.   

    select 
        by_examine_person,
        sum(self_score)  /count(distinct examine_person),
        sum(profes_score)/count(distinct examine_person),
        examine_year 
    from 
        examtrade 
    group by 
        by_examine_person,examine_year
      

  4.   

    不好意思HQL没用过,建议看这个,也许对你有点帮助
    http://blog.csdn.net/ezerg/archive/2004/12/07/208104.aspx
      

  5.   

    这个blog我看一了.他里面的hql没有我现在这个麻烦.有些表示我也不是太清楚.我做其它的也和他的差不多:如select he.byExaminePerson,he.examineYear from HumanExamtrade he
      

  6.   

    对了.如果把你写那个sum(self_score)/count(distinct examine_person)n改为avg(sum(self_score))这样的方式有处理的方法吗?
      

  7.   

    sql中没有这种写法。至于hql中怎么写,那就有待高手出现帮你解决了。
      

  8.   

    我没有见到过有这种写法,我想应该是可以实现.但是一试却出现了错误,根本生不成所要的sql,也多谢你了.
      

  9.   

    select by_examine_person, examine_year,avg(self_score),avg(profes_score)
    from(
    select by_examine_person, examine_year,sum(self_score),sum(profes_score) 
    from examtrade group by by_examine_person,examine_year, examine_person)
    group by by_examine_person,examine_year