mysql错误:以前找到了别名

时间:2016-07-23 20:21:22

标签: mysql

我在mysql查询中使用这些代码

    select c1.date,sum(SELECT IFNULL(cx.purchase-cx.sold,0))+MAX(p.openqty) as opening,c1.purchase,c1.sold,
    sum(SELECT IFNULL(cx.purchase-cx.sold,0))+MAX(p.openqty) + c1.purchase-c1.sold as closing 
from 
    (select open_qty as openqty from stock ) p
left join
(select IFNULL(a.date,b.date) as date,SELECT IFNULL(a.qty,0) as purchase,SELECT IFNULL(b.qty,0) as sold from arrival a FULL JOIN pouring b ON a.date = b.date order by 1) c1 
on c1.purchase +p.openqty>0
left join
 (select IFNULL(a.date,b.date) as date,SELECT IFNULL(a.qty,0) as purchase,SELECT IFNULL(b.qty,0) as sold from arrival a FULL JOIN pouring b ON a.date = b.date order by 1) cx 
on c1.date>cx.date
 group by c1.date,c1.purchase,c1.sold

它说:

An alias was previously found. (near "purchase" at position 170)
An alias was previously found. (near "c1" at position 179)
An alias was previously found. (near "sold" at position 182)
An alias was previously found. (near "closing" at position 190)

MySQL说:文档

  

1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以获得正确的语法