[SQL ] 關於一個子查詢
大家好
我是使用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
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):