-1

我有数据,

Stamp                dataField1 dataFiel2
2012-05-23 23:59:59  ....        ....
2012-05-23 23:50:00  ....        ....
2012-05-24 24:43:23  ....        ....
2012-05-24 24:12:10  ....        ....
2012-05-25 25:15:00  ....        ....
2012-05-26 25:53:59  ....        ....

我想选择每一天的最后一行,结果应该是 li

Stamp                dataField1 dataFiel2
2012-05-23 23:59:59  ....        ....
2012-05-24 24:43:23  ....        ....
2012-05-26 25:53:59  ....        ....
4

4 回答 4

0
SELECT MAX(Stamp) as Last, other_column FROM table GROUP BY DAY(Stamp)
于 2012-12-19T08:12:45.630 回答
0
SELECT Stamp, dataField1, dataFiel2  FROM tableName 
GROUP BY Stamp ORDER BY Stamp ASC
于 2012-12-19T08:19:12.107 回答
0

这个怎么样?

SELECT MAX(Stamp) as Stamp, dataField1, dataField2
FROM tableName
GROUP BY DAYOFYEAR(Stamp)

我会说使用 而不是像每个人所说的那样。不同之处,请参见下面的链接。DAYOFYEAR DAY

演示

在这个演示中,DAY给出了 3 行是不正确的,而不是4 行使用DAYOFYEAR.

于 2012-12-19T08:19:29.757 回答
0

试试这个查询 -

SELECT
  Stamp, dataField1, dataField2, dataField3
FROM
  (SELECT * FROM table ORDER BY Stamp DESC) t
GROUP BY
  DATE(Stamp)
于 2012-12-19T08:27:50.220 回答