作者Arim (Arim5566)
看板Database
标题[SQL ] 关於一个子查询
时间Fri Dec 23 00:15:18 2011
大家好
我是使用sql server 2008
想请问一个sql如下
select "team name"
from (select player.[Team Name] ,SUM (cast(H as int)) as total from Score
inner join Player on Score.[Player Name]=Player.[Player Name] inner join List
on Player.[Team Name]=List.[Team Name] where League='Nations League' group by
player.[Team Name]) as A
where A.total=(select MAX(total) from A ) /*不懂为啥系统会说A是无效的物件*/
因为我在from的地方已经建立了A
可是在where要用子查询查A的时候,系统会说A是无效的物件...
我的schema是这样子
player(player name,team name)
score(player name,H)
List(Team Name,League)
我的目的是要找出League='Nations League'而且H(安打)总和是最大的Team name
不知道为什麽会造成在where的子查询没办法用到在from利用as建立的别名A
可是A.total是存在的呀~"~
谢谢各位版友的指教
--
~宅男的四个徵兆~
∠□ ○ ! * \○/ ★ (○ ?
╦╦└□ " ○□═ □ □>
║║√√ ╦══╦ ∥ |\
一回家就上PTT 每天想正妹 以当好人为乐 忘记正妹亏欠自己
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.32.197.57