我有一个名为“ versions”的表,该表的列为control_no,version_id,revision_dt,version_no,version_dt,created_by,change_type,summary,new_owner。
每个control_no的version_id范围从1到特定数字。我要从此表中选择 VERSION_NO,CHANGE_TYPE,SUMMARY,CREATED_BY,表示CONTROL_NO(最大值(REVISION_ID))。
如何执行此操作?
答案 0 :(得分:0)
使用以下查询
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);
答案 1 :(得分:0)
通过以下代码,您可以获取
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
答案 2 :(得分:0)
这将起作用:
select VERSION_NO,CHANGE_TYPE,SUMMARY,CREATED_BY,max(REVISION_ID),control_no
from versions group by control_no;