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 に答える