为什么sql中的max函数返回多个值 [英] Why does max function in sql return multiple values

查看:60
本文介绍了为什么sql中的max函数返回多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示薪水最高的球员.

I would like to display the player with the highest salary.

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]

输出为:

highest_salary  Last Name
   8000          Bosh
   7000          Wade
   6000          James

我只想显示(8000 Bosh 因为他是薪水最高的球员).

I just want to display (8000 Bosh since he is the player with highest salary).

推荐答案

你不需要 MAX 也不需要 GROUP BY,只要使用 TOP 1code> 和 ORDER BY Salary DESC.像这样:

You did't need MAX nor GROUP BY, just use TOP 1 with ORDER BY Salary DESC. Something like this:

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

这篇关于为什么sql中的max函数返回多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆