0

无法理解如何进行选择:表结构:

id name value date
1 ivan    2    2010-01-01
2 ivan    3    2010-05-08
3 ivan    1    2009-04-14
4 sasha   2    2011-11-11
5 sasha   9    2012-04-04

怎么获得?:

name value(in last time)
ivan  3
sasha 9
4

4 回答 4

2

这是未经测试的,但应该可以工作:

SELECT
    name,
    MAX(value)
FROM
    structure
GROUP BY
    name
于 2012-04-20T11:36:49.673 回答
1

此查询应该有效

select f.name, f.value, f.date
from (
   select id,name,max(date) as dat from tableName group by name
) as x inner join tableName as f on f.name = x.name and f.date = x.dat;
于 2012-04-20T12:11:07.670 回答
0
SELECT DISTINCT name, value FROM table ORDER BY date DESC

到目前为止,这就是我从您目前的描述中所理解的。

于 2012-04-20T11:37:08.777 回答
0

像这样的东西:

SELECT
    MAX(value),
    name
FROM
    Table
GROUP BY
    name
于 2012-04-20T11:37:38.993 回答