我有一张表格,我想在哪里获得一行最大值。 我正在尝试:
select max(version) as max, curr_ver, creation_date, nameJob from schema.def where nameJob = 'try'
group by curr_ver,creation_date,nameJob;
我明白了:
VERSION CREATION_DATE NAMEJOB CURR_VER
------- -------------- -------- ---------
2 20180301 TRY N
1 20180307 TRY Y
我只想得到(最大行)
VERSION CREATION_DATE NAMEJOB CURR_VER
------- -------------- -------- ---------
2 20180301 TRY N
你知道我做错了什么吗? 谢谢,抱歉我的英文!
答案 0 :(得分:1)
如果您希望row
的值具有max
组最大值,那么这样的事情就可以了:
select max(version) as max, curr_ver, creation_date, nameJob
from schema.def
where nameJob = 'try'
group by curr_ver,creation_date,nameJob
having
max(version) = (select max(version) as global_max from schema.def
where nameJob = 'try');