11

我的子查询给出了一个错误:Msg 102, Level 15, State 1, Line 17 Incorrect syntax near ')'.

SELECT SalesArea, Branch, Volume
from
(select 
br.SalesArea as SalesArea
,br.Branch as Branch
, sum(a.Volume) as Volume
FROM dbo.vDetail a with (nolock) 
LEFT JOIN
dbo.vBranch AS br WITH (nolock) 
ON a.Branch = br.Branch
group by a.Volume, br.SalesArea, br.Branch)
4

3 回答 3

12

您缺少子查询的别名试试这个。

SELECT SalesArea, Branch, Volume
from
(select 
br.SalesArea as SalesArea
,br.Branch as Branch
, sum(a.Volume) as Volume
FROM dbo.vDetail a with (nolock) 
LEFT JOIN
dbo.vBranch AS br WITH (nolock) 
ON a.Branch = br.Branch
group by a.Volume, br.SalesArea, br.Branch) as x
于 2012-07-20T08:55:04.923 回答
7

每个子查询中的选择都需要一个别名。只需在末尾添加一个“X”,它将成为表的名称

不好:

select * from (
   select * from your_table
) 

好的:

select * from (
   select * from your_table
) X
于 2012-07-20T09:01:30.530 回答
1

您需要派生表的别名

SELECT SalesArea, Branch, Volume 
from 
(select  
br.SalesArea as SalesArea 
,br.Branch as Branch 
, sum(a.Volume) as Volume 
FROM dbo.vDetail a with (nolock)  
LEFT JOIN 
dbo.vBranch AS br WITH (nolock)  
ON a.Branch = br.Branch 
group by a.Volume, br.SalesArea, br.Branch) as T
于 2012-07-20T08:55:20.537 回答