不能为我的生活了解查询中的错误所在

时间:2013-11-02 17:07:49

标签: mysql sql

收到此错误:

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'rMin left join select * from  ( ( select  symbol,(dt) as dt,callPut,bid,ask,stri' at line 15

在以下查询中:

            select * from (
            select * from 
            (
            (
            select 
            symbol,(dt) as dt,callPut,bid,ask,strike,maturity,`Open Int`,impVol,theta,delta from bats.Opt where impVol>0 
            ) as a1
            inner join
            (select 
            symbol,min(dt) as dt from bats.Opt where impVol>0 
            group by symbol
            ) as b1
            on a1.symbol=b1.symbol and a1.dt=b1.dt 
            )
            as rMin
            left join
            select * from 
            (
            (
            select 
            symbol,(dt) as dt,callPut,bid,ask,strike,maturity,`Open Int`,impVol,theta,delta from bats.Opt where impVol>0 
            ) as a1
            inner join
            (select 
            symbol,max(dt) as dt from bats.Opt where impVol>0 
            group by symbol
            ) as b1
            on a1.symbol=b1.symbol and a1.dt=b1.dt 
            )
            as rMax

            on rMax.symbol=rMin.symbol
            )

1 个答案:

答案 0 :(得分:1)

我首先要格式化查询,以便您可以轻松阅读,匹配括号等等。

然后,我会运行每个子查询以确保它们在语法上是正确的。

但是,在这之前,我会在最后一个结束括号后添加一个表别名。 MySQL要求from子句中的子查询具有表别名。不可否认,这个错误更具描述性“每个派生表必须有自己的别名”,所以这可能无法解决整个问题。