Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use sql to count the amount of data in every ten minutes

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

In mysql database, use SQL to calculate the amount of data within ten minutes.

Let's start with the table structure:

The desired result is: how many user_id are there every ten minutes?

Option 1:

Select from_unixtime (floor (UNIX_TIMESTAMP (start_time) / 600) * 600), COUNT (DISTINCT user_id) AS 'count' from user_live_hits_log_history

Group by FLOOR (UNIX_TIMESTAMP (start_time) / 600)

Scheme 2:SELECT RPAD (LEFT (start_time,15), 1914) AS start_time, COUNT (DISTINCT user_id) AS 'count' FROM user_live_hits_log_history GROUP BY LEFT (start_time,15)

As long as you are familiar with the application of these functions, you will find it very simple.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report