我有数据,
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 .... ....
我希望选择每一天的最后一行,结果应该看起来像
Stamp dataField1 dataFiel2
2012-05-23 23:59:59 .... ....
2012-05-24 24:43:23 .... ....
2012-05-26 25:53:59 .... ....
答案 0 :(得分:0)
SELECT MAX(Stamp) as Last, other_column FROM table GROUP BY DAY(Stamp)
答案 1 :(得分:0)
SELECT Stamp, dataField1, dataFiel2 FROM tableName
GROUP BY Stamp ORDER BY Stamp ASC
答案 2 :(得分:0)
这个怎么样?
SELECT MAX(Stamp) as Stamp, dataField1, dataField2
FROM tableName
GROUP BY DAYOFYEAR(Stamp)
我会说使用 DAYOFYEAR
而不是 {{每个人都说1}} 。有关差异,请参阅以下链接。
在此演示中,DAY
提供3行 INCORRECT ,与使用DAY
的4行相对。
答案 3 :(得分:0)
尝试此查询 -
SELECT
Stamp, dataField1, dataField2, dataField3
FROM
(SELECT * FROM table ORDER BY Stamp DESC) t
GROUP BY
DATE(Stamp)