MySQL为每个唯一标题获取2个最新记录

时间:2017-03-28 05:36:50

标签: mysql greatest-n-per-group

说我有下表:

Type        |Price   |Time      
-------------------------
Drill       | 5      | ---
Drill       | 2      | ---
Drill       | 1      | ---
Plant       | 3      | ---
Plant       | 4      | ---
Light Plant | 9      | ---
Light Plant | 21     | ---
Light Plant | 1      | ---
Light Plant | 5      | ---

我想获得每种类型的2条最新记录。 所以这是我期待的输出:

Drill       | 5
Drill       | 2
Plant       | 3
Plant       | 4
Light Plant | 9
Light Plant | 21

我有一个包含多个查询的工作解决方案,即每个查询查找特定类型的2个最新记录。循环遍历所有唯一类型。但是,我想用一个查询来完成它。

0 个答案:

没有答案