“where”附近的SQL语法错误

时间:2013-07-12 10:04:36

标签: sql syntax-error where

我是个新手。这可能很容易解决。

查询:

select AvgR.preavgMR - AvgR.postavgMR
from (
    ((select R.mID mID, avg(R.stars) preavgMR from Rating R group by R.mID)
    join Movie M using (mID)
    where year < 1980
    )
    join    
    ((select R.mID mID, avg(R.stars) postavgMR from Rating R group by R.mID)
    join Movie M using (mID)
    where year >= 1980
    )
) AvgR using (mID);

结果:

Query failed to execute: near "where": syntax error

思想/建议?谢谢!

1 个答案:

答案 0 :(得分:0)

尝试这种方式:

select AvgR.preavgMR - AvgR.postavgMR
from (
    ( 
      select mID,preavgMR
      from (select R.mID mID, avg(R.stars) preavgMR from Rating R group by R.mID) T1
      join Movie M using (mID)
       where year < 1980
    )
    join    
    (
      select mID,postavgMR 
      from (select R.mID mID, avg(R.stars) postavgMR from Rating R group by R.mID) T2
    join Movie M using (mID)
    where year >= 1980
    )
) AvgR;