mysql - Get records with highest value grouped by datetime hourly -


I think the description of variation in common case

this data The table is with

  id. Value1 Value 2 Curdate | Curetime 1 | 234 | 500 2014-10-27 | 12:00:00 2 200. 400 2014-10-27 | 12:05:00 3 300 600 | 2014-10-27 | 12:10:00 4 400 800 | 2014-10-27 | 12:15:00 5 150 700 2014-10-27 | 12:20:00 ... 10 | 134 | 530 | 2014-10-27 | 13:00:00 12. 220 | 420 2014-10-27 | 13:05:00 13 | 330 | 630 | 2014-10-27 | 13:10:00 14. 440 | 840 | 2014-10-27 | 13:15:00 15. 120 | 750 2014-10-27 | 13:20:00  

I need a maximum cost of 2 hours per hour report and the same value is 1:

  value1 | Value 2 Curdate | Curium 400 | 800 | 2014-10-27 | 12:00:00 440. 840 | 2014-10-27 | 13:00:00  

I was trying to implement the "standard" solution specified in the answer above, but using no MySQL success.

  SELECT T1 * Type T1 from the table as 'OUTER' as 'TABLE' on T2 on T2. GroupID = T2. Group IID and T1 Orderfield & lt; T2.OrderField WHERE t2.GroupId is NULL  

I tried to do something like this:

  SELECT T1 * Join the T1 left OUTER table from the table AS T2 ON SUBSTR (Konkat (T1Crideadet, '', T1Curtame), 1, 13) = SUBSTR (Konkat (T2cured, '', T2Chrittum), 1, 13) and T1. Value 2 & lt; T2.value2 ou ???? IS is tap & lt; --- Not sure what to be kept here  

Please help Thanks. Sample data:

  create table (`id` integer,  

`Value1`it,` value2` transmitted, date of `curdate`, 'curum time'); Enter value in value (T, `id`,` value1`, `value2`,` curdate`, `curum`] (1, 234, 500, '2014-10-27', '12: 00: 00 '), (2, 200, 400,' 2014-10-27 ', '12: 05: 00'), (3, 300, 600, '2014-10-27', '12: 10: 00 ') , (4, 400, 800, '2014-10-27', '12: 15: 00 '), (5, 150, 700,' 2014-10-27 ', '12: 20: 00'), ( 10, 134, 530, '2014-10-27', '13: 00: 00 '), (12, 220, 420,' 2014-10-27 ', '13: 05: 00'), (13, 330, 630, '2014-10-27', '13: 10: 00 '), (14, 440, 840,' 2014-10-27 ', '13: 15: 00'), (15, 120, 750, '2014 -10-27', '13: 20: 00 ');

Question:

  SELECT t * Join ININER (SELECT DATE_FORMAT (CONCAT (curdate, '', curtime, '% Y-% M-% d% h') as the date, MAX (value 2) maxv2, FROM T group by datehore) Sq ON t.value2 = sq.maxv2 and DATE_FORMAT (CONCAT (t.curdate, '', krtmay), '% Y-% m-% d% h') = sq.datehour;  

Result:

  + ------ + -------- + -------- + - ----------- + ---------- + | ID | Value1 Value 2 Curdate | Curitiba | + ------ + -------- + -------- + ------------ + ---------- + | 4 | 400 800 | 2014-10-27 | 12:15:00 pm | 14 | 440 | 840 | 2014-10-27 | 13:15:00 | + ------ + -------- + -------- + ------------ + ---------- +  

Comments