无法理解如何进行选择:表结构:
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
无法理解如何进行选择:表结构:
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
这是未经测试的,但应该可以工作:
SELECT
name,
MAX(value)
FROM
structure
GROUP BY
name
此查询应该有效
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;
SELECT DISTINCT name, value FROM table ORDER BY date DESC
到目前为止,这就是我从您目前的描述中所理解的。
像这样的东西:
SELECT
MAX(value),
name
FROM
Table
GROUP BY
name