2018-05-19 mssql 的select from (select from )使用的限制

可以使用,可以运行,

但是 要给 (select from) as alias 别名(e.g kk) ,加别名可用。 


select

kk.OlympicYear,

kk.Country

from

(

select

sum(Gold_Medals) as Total_GM,

sum(Silver_Medals)as Total_SM,

sum(Bronze_Medals) as Total_BM,

sum(Gold_Medals + Silver_Medals + Bronze_Medals) as Total_Medals,

main.OlympicYear,

main.Country

from OlympicAthletes as main

left join (

select

AthleteID,

Athlete,

CONVERT(VARCHAR(10),  Closing_Ceremony_Date, 101) as formatdate,

(3*Gold_Medals + 2*Silver_Medals + Bronze_Medals)as Medal_Weight,

OlympicYear,

Country

from OlympicAthletes

) as minor

on main.OlympicYear = minor.OlympicYear and main.Country = minor.Country

group by main.OlympicYear,main.Country

) as kk

你可能感兴趣的:(2018-05-19 mssql 的select from (select from )使用的限制)