Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm working on creating Google Charts from MySQL datasource. This works fine so far. Now I want to count how many blocks of a Blockchain processed per hour.

How can I simple substract the first row from last row of a group?

SELECT
   date_format(time,'%Y-%m-%d %H-%i'),blocks,
   count(1)
FROM blockchain
GROUP BY 1  
ORDER BY `date_format(time,'%Y-%m-%d %H-%i')` ASC

And if this done, how to repeat this for the last 24 hours?

Sample data:

id          time                        blocks

3           2020-12-30 11:21:53         112149
4           2020-12-30 11:21:55         112150
5           2020-12-30 11:21:56         112150
6           2020-12-30 11:21:57         112150
7           2020-12-30 11:24:01         112169
8           2020-12-30 11:25:01         112178
9           2020-12-30 11:26:01         112188
10          2020-12-30 11:27:01         112197



-10         2020-12-30 11:27:01         112197
 3          2020-12-30 11:21:53         112149
-----------------------------------------------
                                        48                                       

I hope its not a stupid question. I'm kinda new to this.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
310 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use this query to get blocks per hour.

select hour(time) as hr, max(blocks)-min(blocks) as blocks_per_hour
from test
group by hour(time)

Result:

hr blocks_per_hour
11 48

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...