mardi 24 mai 2016

Get the last value of created_at date with distinct value column

I have the same problem for a lot of days ago, I have a table with a lot of values associated with her sensors in a MongoDB. Then I have to get all this distincts sensors, BUT I have to take the last value, Ex:

value---sensor---created_at
---------------------------
25---1---2016-05-09 16:33:51

68---1---2016-06-09 16:33:51

13---1---2016-07-09 16:33:51

12---3---2016-05-09 16:33:51

22---3---2016-06-09 16:33:51

I need to take the last value of the sensor 1:

13---1---2016-07-09 16:33:51

And the last value of the sensor 2:

22---3---2016-06-09 16:33:51

But I can't TT;

I try to do this:

Value::select('sensor', 'value', 'created_at')->orderBy('created_at', 'DESC')->groupBy('user_sensor_type_id')->get();

But it returns me random values, not the last.

Any ideas?

Thanks a lot!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire