Left Join on Same table - 不识别嵌套的SELECT语句

时间:2012-06-06 20:27:03

标签: sql

我试图根据同一个表中的不同条件提取两个不同的值,并且在同一个表的左连接中,它不识别SELECT语句。

错误如下:

Dynamic SQL Error
SQL error code = -104
Token unknown - line 7, char -1
SELECT.

SQL语句:

SELECT
b.dept,b.typ,c.brand,c.style,c.ext,c.description,
max(c.price),max(c.last_cost),sum(c.quan) "TOTAL INV",D.QUAN "WEB INV"
FROM
invt c
left outer join (
    SELECT dept,typ,brand,style,ext,description,sum(quan) as d.quan
    FROM invt WHERE store in ('997')
    group by dept,typ,brand,style,ext,description) d 
on (b.store = d.store and b.style = d.style and b.brand = d.brand)
LEFT OUTER JOIN
sku b
on c.style = b.style and c.brand = b.brand
where c.quan <> 0 or c.ord <> 0
GROUP BY
b.dept,b.typ,c.brand,c.style,c.ext,c.description

1 个答案:

答案 0 :(得分:1)

尝试更改此行:

SELECT dept,typ,brand,style,ext,description,sum(quan) as d.quan

到此:

SELECT store,dept,typ,brand,style,ext,description,sum(quan) as quan

此处不需要d别名。

更新:

正如@Jeremy Holovacs所提到的,您似乎也在使用d.store进行连接,但它在子查询中不存在。