This question already has an answer here:
这个问题在这里已有答案:
- Fetch the row which has the Max value for a column 34 answers
获取具有列34答案的最大值的行
I have a table named 'versions' which has columns control_no, revision_id ,revision_dt, version_no, version_dt, created_by, change_type, summary, new_owner.
我有一个名为'versions'的表,其中包含control_no,revision_id,revision_dt,version_no,version_dt,created_by,change_type,summary,new_owner。
Each control_no has revision_id ranging from 1 to a specific number. From this table, I want to select VERSION_NO,CHANGE_TYPE,SUMMARY,CREATED_BY for a CONTROL_NO with max(REVISION_ID).
每个control_no的revision_id范围从1到特定数字。从该表中,我想为具有max(REVISION_ID)的CONTROL_NO选择VERSION_NO,CHANGE_TYPE,SUMMARY,CREATED_BY。
How to do this?
这该怎么做?
3 个解决方案
#1
0
Use the below query
使用以下查询
select VERSION_NO,CHANGE_TYPE,SUMMARY,CREATED_BY from VERSIONS where REVISION_ID in (SELECT A.REVISION_LIST FROM (select max(REVISION_ID) AS REVISION_LIST, CONTROL_NO AS CONT_NO from VERSIONS GROUP BY CONTROL_NO)A);
#2
0
this will work:
这将工作:
select VERSION_NO,CHANGE_TYPE,SUMMARY,CREATED_BY,max(REVISION_ID),control_no
from versions group by control_no;
#3
0
By Below Code you can get
通过以下代码,你可以得到
SELECT MAX(Version_id) AS Version_id, VERSION_NO,CHANGE_TYPE,SUMMARY,CREATED_By, CONTROL_NO
from table
GROUP BY VERSION_NO,CHANGE_TYPE,SUMMARY,CREATED_By, CONTROL_NO
#1
0
Use the below query
使用以下查询
select VERSION_NO,CHANGE_TYPE,SUMMARY,CREATED_BY from VERSIONS where REVISION_ID in (SELECT A.REVISION_LIST FROM (select max(REVISION_ID) AS REVISION_LIST, CONTROL_NO AS CONT_NO from VERSIONS GROUP BY CONTROL_NO)A);
#2
0
this will work:
这将工作:
select VERSION_NO,CHANGE_TYPE,SUMMARY,CREATED_BY,max(REVISION_ID),control_no
from versions group by control_no;
#3
0
By Below Code you can get
通过以下代码,你可以得到
SELECT MAX(Version_id) AS Version_id, VERSION_NO,CHANGE_TYPE,SUMMARY,CREATED_By, CONTROL_NO
from table
GROUP BY VERSION_NO,CHANGE_TYPE,SUMMARY,CREATED_By, CONTROL_NO