加入两张桌子,获得最高薪水 [英] Join the two tables and get the highest salary
本文介绍了加入两张桌子,获得最高薪水的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两张表格,其定义如下:
I have a two tables with the same table definitions as follows:
COL1 CO2
1 1000.00
2 2000.00
3 3000.00
4 4000.00
5 5000.00
COL1 CO2
1 1500.00
2 2000.00
3 77000.00
4 80000.00
5 51500.00
通过使用联接,我需要如下最高薪水:
CO2
800000
By using joins, I need highest salary like as follows:
CO2
800000
推荐答案
检查这个...
Hi,
Check this...
SELECT MAX(CO2) FROM
(
SELECT CO2 FROM TBL1
UNION
SELECT CO2 FROM TBL2
)X
希望这个会帮助你。
干杯
Hope this will help you.
Cheers
As King Fisher [ ^ ]在问题评论中提及,您 - 可能 - 需要使用UNION
代替JOIN
。
As King Fisher[^] mentioned in comment to the question, you - probably - need to useUNION
instead ofJOIN
.
SELECT MAX(col2)
FROM (
SELECT col1, col2
FROM Table1
UNION ALL
SELECT col1, col2
FROM Table2
) AS T
试试这样:
1)
Try like this:
1)
select max(t.col1 )
from (
select *From table3 union all
select *From table2
)as t
或
2)
or
2)
select top 1 col1
from (
select * From table3 union all
select * From table2
)as t
order by col1 desc
这篇关于加入两张桌子,获得最高薪水的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文