I have a table with value look like this
id time_stamp value
1 2013-01-01 00:00:15 10
2 2013-01-01 01:00:15 5
3 2013-01-02 00:00:15 15
4 2013-01-02 01:00:15 20
5 2013-02-01 00:00:15 18
6 2013-02-01 01:00:15 15
7 2013-02-02 00:00:15 5
8 2013-02-02 01:00:15 17
9 2014-01-01 00:00:15 8
10 2014-01-01 01:00:15 5
11 2014-01-02 00:00:15 15
12 2014-01-02 01:00:15 30
13 2014-02-01 00:00:15 18
14 2014-02-01 01:00:15 15
15 2014-02-02 00:00:15 5
16 2014-02-02 01:00:15 17
From this table I want to select the first record value and the last record value based on hour, day, month, year
For example I select value based on
Day:
id time_stamp start_value end_value
1 2013-01-01 10 5
2 2013-01-02 15 20
3 2013-02-01 18 15
and so on
Month:
id time_stamp start_value end_value
1 2013 jan 10 20
2 2013 feb 18 17
3 2014 jan 8 30
4 2014 feb 18 17
Year:
id time_stamp start_value end_value
1 2013 10 17
2 2014 8 17
How can I do this?
Use mysql’s aggregation functions such as the following
I’ve provided extra parameters on the query, to help you by keeping the query flexible 🙂