天生舞男

我喜欢谦虚的学习各种...,希望自己能坚持一辈子,因为即使一张卫生巾也是有它的作用.
随笔 - 76, 文章 - 4, 评论 - 39
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

多个平均数列的子查询

Posted on 2008-01-09 18:08  天生舞男  阅读(212)  评论(0编辑  收藏
SELECT company_name, title, teachername, company.id,average
    FROM companies company
    left outer join (select ROUND(avg(score), 2) as average, company_id
       from companycomments
       group by company_id) companycomments
    on company.id = companycomments.company_id
    left outer join
    (
     select company_id, title,teachername
     from trainings, teachers, teachers_trainings
     where teachers.id = teachers_trainings.teacher_id
           and teachers_trainings.training_id = trainings.id
    ) totalInfo
    on company.id = totalInfo.company_id