找出价格高于平均价格的产品select projectId,name,price from product outer where price >(select avg(price) from product inner where inner.projectId=outer.projectId)这里如果没有inner.projectId=outer.projectId这个条件行不行?我是想先执行里面的,在执行外面的就不用inner.projectId=outer.projectId来连接了。不知道这种想法对不对,谢谢

解决方案 »

  1.   

    inner.projectId=outer.projectId 这是把这两个表连接起来进行查询,得到avg(price),如果没的的话,所找出的数据就没的条件限制,和product outer表就没的对应了。我也是新手,不知道意见正确不!
      

  2.   

    select projectId,name,price from product  where price>(select avg(price) from product)
      

  3.   

    楼主其实可以不用那么写
    select projectId,name,price from product T where price >(select avg(price) from product T1 where T1.projectId=T.projectId)
    可以向上面那么写,就是给两个表起了个别名,访问时用别名