簡體   English   中英

SQL子查詢錯誤附近)

[英]SQL Subquery error near )

我的子查詢給出錯誤: 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)

你缺少子查詢的別名試試這個。

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

子查詢中的每個選擇都需要別名。 只需在最后添加一個“X”,它將成為表的名稱

不好:

select * from (
   select * from your_table
) 

好:

select * from (
   select * from your_table
) X

您需要派生表的別名

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM