-1

i have data,

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  ....        ....

and i want to select every day last row and result should look li

Stamp                dataField1 dataFiel2
2012-05-23 23:59:59  ....        ....
2012-05-24 24:43:23  ....        ....
2012-05-26 25:53:59  ....        ....
4
  • What have you tried? Dec 19, 2012 at 8:07
  • Is there an ID column in that table?
    – Salman A
    Dec 19, 2012 at 8:09
  • What is the data type of the column Stamp? If it is a datetime, how it can be a time like 24:43:23 or 25:53:59? Dec 19, 2012 at 8:11
  • @MahmoudGamal : I believe OP was putting raw data and missed that... from 23 he increased time by 1... so it is 23...24...25 Dec 19, 2012 at 8:28

4 Answers 4

0

How about this?

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

I would say use DAYOFYEAR instead of DAY as everyone stated. For difference, see below link.

Demo

In this demo, DAY gives 3 rows which is INCORRECT as oppose to 4 rows using DAYOFYEAR.

3
  • dataField1 and dataField2 can be from arbitrary rows in each day, not necessarily the last row of each day.
    – Barmar
    Dec 19, 2012 at 8:24
  • @Barmar : I don't get what you want to say... Dec 19, 2012 at 8:26
  • This answer is incorrect as dataField1, dataField2 would be random values.
    – nowhere
    May 10, 2016 at 13:46
0
SELECT MAX(Stamp) as Last, other_column FROM table GROUP BY DAY(Stamp)
0
SELECT Stamp, dataField1, dataFiel2  FROM tableName 
GROUP BY Stamp ORDER BY Stamp ASC
0

Try this query -

SELECT
  Stamp, dataField1, dataField2, dataField3
FROM
  (SELECT * FROM table ORDER BY Stamp DESC) t
GROUP BY
  DATE(Stamp)

Not the answer you're looking for? Browse other questions tagged or ask your own question.