我有一张桌子,看起来像这样:
如何获得具有最大年份和sem的所有ID?
SELECT m.ID,
MAX(m.Year) as MaxYearLevel,
m.Sem
FROM
(SELECT t1.ID AS StudentID,
t1.Year,
t1.Sem
FROM table1 t1) AS m
GROUP BY m.ID;
答案 0 :(得分:0)
只需按
执行订单Select * from [Your table] order by year DESC, sem DESC
并指定您要拍摄的行数
ORACLE SQL:
Select * from [Your table] order by year DESC, sem DESC fetch first x rows only
SQL:
select Top(x) * from [Your table] order by year DESC, sem DESC