use*_*418 0 sql-server sql-server-2005
我想展示薪水最高的球员.
select max(Salary) as highest_salary, p.[Last name]
from tbl_PlayersTable as p, tbl_team as t
where p.Team = t.TeamID
and TeamID = 1000
Group by p.[Last name]
Run Code Online (Sandbox Code Playgroud)
输出是:
highest_salary Last Name
8000 Bosh
7000 Wade
6000 James
Run Code Online (Sandbox Code Playgroud)
我只想表现出来(因为他是薪水最高的球员,因此他有8000名波什).
你我以前不需要MAX也不是GROUP BY,只要使用TOP 1同ORDER BY Salary DESC.像这样的东西:
select TOP (1) Salary as highest_salary, p.[Last name]
from tbl_PlayersTable as p, tbl_team as t
where p.Team = t.TeamID
and TeamID = 1000
ORDER BY Salary DESC
Run Code Online (Sandbox Code Playgroud)