【发布时间】:2011-08-26 01:06:13
【问题描述】:
我的表格中有一些重复的值,我只想选择那些日期最新/最高的值,即:
ID Type Name Value Date
-- ------- ----- ------- -------------
1 "FRUIT" "APPLE" "Imported" "2011-03-19 22:08:13"
5 "FRUIT" "LEMON" "Imported" "2011-03-19 22:00:44"
22 "FRUIT" "PEACH" "Imported" "2011-03-20 11:03:13"
31 "FRUIT" "MELON" "Imported" "2011-04-28 18:42:07"
44 "FRUIT" "PEACH" "Imported" "2011-04-12 11:06:11"
98 "FRUIT" "CHERRY" "Imported" "2011-03-19 22:46:04"
211 "FRUIT" "MELON" "Imported" "2011-03-19 22:25:24"
217 "VEG" "SPINACH""Imported" "2011-03-19 22:25:24"
我想选择这些:
ID Type Name Value Date
-- ------- ----- ------- -------------
1 "FRUIT" "APPLE" "Imported" "2011-03-19 22:08:13"
5 "FRUIT" "LEMON" "Imported" "2011-03-19 22:00:44"
31 "FRUIT" "MELON" "Imported" "2011-04-28 18:42:07"
44 "FRUIT" "PEACH" "Imported" "2011-04-12 11:06:11"
98 "FRUIT" "CHERRY" "Imported" "2011-03-19 22:46:04"
这是我需要的简化版,我的表大约有20列所以我想选择*,如果没有我可以一一选择。
所以我想选择 * 行类型 FRUIT 但只选择日期最高的那些。谢谢
【问题讨论】:
-
我想我理解你,但你的解释有点模糊,下面有两种不同类型的答案。你想要每种水果中的一种,对吗?如果相同的水果被列出两次或更多,请获取最近的一个?
标签: mysql sql hibernate postgresql