首页 > 解决方案 > 如何在 MS Access SQL 上选择最多两列并按站分组

问题描述

我有一个像这样的简单表

 station    num     tim
 -------------------------
   1       150       10
   1       200      222
   1       100     5000
   1       200      555
   2       100      500
   2       120      200
   3         1        2

所需的输出是这样的:

station  num     tim
---------------------
   1     200     555
   2     120     200
   3       1       2

但我不能使用ROW_NUMBER(),因为查询需要在 MS Access SQL 中执行。

谁能帮我?

标签: sqlms-accessselect

解决方案


你也可以试试这个:

select t2.station,t1.num as num,max(t2.tim) tim from (select max(num) num  
from tablename group by station) t1
join tablename on t1.num = t2.num group by t1.num,t2.station

推荐阅读