A
A
Alexey Sklyarov2019-01-29 19:44:25
Laravel
Alexey Sklyarov, 2019-01-29 19:44:25

How to take values ​​from the database not for every minute, but for every 5 minutes?

The price value is added to the database once a minute, if I make a selection for the whole day, then I will show all the price values ​​​​for each minute, but is it possible to somehow "cut" the array so that the values ​​\u200b\u200bare shown for every 5 minutes, respectively all other values ​​were simply deleted and the array would be 5 times smaller?
For example:

| id  | price | time  |
|-----|-------|-------|
| 1   | 100   | 15:01 |
| 2   | 200   | 15:02 |
| 3   | 220   | 15:03 |
| 4   | 115   | 15:04 |
| 5   | 221   | 15:05 |
| 6   | 220   | 15:06 |
| ... | ...   | ...   |
| 10  | 219   | 15:10 |

Convert to this:
| id  | price | time  |
|-----|-------|-------|
| 1   | 221   | 15:05 |
| 2   | 219   | 15:10 |

UPD: the time is naturally stored in the timestamp in the database

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
grinat, 2019-01-29
@0example

Convert time to number via select TIME_TO_SEC(time) as seconds and output those records that are multiples of 60*5 where (seconds mod 300) == 0 If orm, then use Raw Expressions to insert such expressions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question