如何从三表获取共同的最大元素
我有三张表A,表B和表C 所有三个表都有一个通用的列。
如何从三个表中获取共同的最大值?
这是我的表信息:
表A
id salary
101 10000
102 15000
103 18000
表B
id salary
110 14000
127 21000
118 15000
表C
id salary
191 15000
192 20000
193 8000
我所需的输出是:
salary
15000
I have three tables called table a, table b and table c
all the three tables have one common column.
How to get the common maximum value from the three tables?
here is my table info:
table a
id salary
101 10000
102 15000
103 18000
table b
id salary
110 14000
127 21000
118 15000
table c
id salary
191 15000
192 20000
193 8000
my required output is :
salary
15000
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
联合所有
(或union
)以使用额外的列来获取所有3个表的薪水然后在中具有
集合查询子句检查是否属于所有表格。最后,使用 限制1 以获取最大common
薪金>薪金
:Use
UNION ALL
(orUNION
) to get the salaries of all 3 tables with an extra column, like anid
, which marks the source table and then in theHAVING
clause of an aggregation query check if that salary belongs to all tables.Finally use
ORDER BY
withLIMIT 1
to get the max commonsalary
:您可以在表之间使用内部连接,以确保您仅考虑所有三个表中发生的值。
然后使用
max()
以获取此类值中的最大值。You can use inner joins between the tables to make sure you're only considering values that occur in all three tables.
Then use
MAX()
to get the greatest of such values.