在两个表之间使用 MAX 聚合

发布于 2024-09-25 00:08:07 字数 329 浏览 2 评论 0原文

我有两个表,雇主和职位:

雇主
电子身份证
eName

职位
电子身份证
我需要

在两个表之间匹配我的 eID,确定最高工资是多少,然后仅打印 eName。关于我如何做到这一点有什么建议吗?我尝试了多种方法,但似乎没有任何效果。

我不知道在哪里放入 max(salary) 函数:

select eName
from employer, position
where employer.eID = position.eID

I have two tables, employer and position:

Employer
eID
eName

Position
eID
salary

I need to match my eID between the two tables, determine what the max salary is, and print only the eName. Any suggestions as to how I can do this? I have tried multiple ways, but nothing seems to work.

I am not sure where to put in the max(salary) function:

select eName
from employer, position
where employer.eID = position.eID

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

话少情深 2024-10-02 00:08:07

要获取薪水最高的人的姓名...

使用 JOIN:

SELECT e.name
  FROM EMPLOYER e
  JOIN POSITION x ON x.eid = e.eid
  JOIN (SELECT MAX(salary) AS max_salary
          FROM POSITION) y ON y.max_salary = x.salary

使用子查询:

SELECT e.name
  FROM EMPLOYER e
  JOIN POSITION p ON p.eid = e.eid
 WHERE p.salary = (SELECT MAX(salary)
                     FROM POSITION)

To get the name(s) of the people with the highest salary...

Using a JOIN:

SELECT e.name
  FROM EMPLOYER e
  JOIN POSITION x ON x.eid = e.eid
  JOIN (SELECT MAX(salary) AS max_salary
          FROM POSITION) y ON y.max_salary = x.salary

Using a subquery:

SELECT e.name
  FROM EMPLOYER e
  JOIN POSITION p ON p.eid = e.eid
 WHERE p.salary = (SELECT MAX(salary)
                     FROM POSITION)
似最初 2024-10-02 00:08:07
select e.ename,p.salary
from employer e ,position p
where p.salary=(select max(salary) from position)
and e.eid=p.eid
select e.ename,p.salary
from employer e ,position p
where p.salary=(select max(salary) from position)
and e.eid=p.eid
云醉月微眠 2024-10-02 00:08:07

连接表,排序,并获取第一个:(

select top 1 e.eName, p.salary
from Employer e
inner join Position p on p.eID = e.eID
order by p.salary desc

这也会返回工资,但如果您真的不想要它,当然可以将其删除。)

Join the tables, sort, and get the first one:

select top 1 e.eName, p.salary
from Employer e
inner join Position p on p.eID = e.eID
order by p.salary desc

(This returns the salary also, but you can of course remove it if you really don't want it.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文