Get the App
SLTechnology News&Howtos  ›  Database  › 

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

Shulou Source: shulou.com Published: 2022-06-01 09:35:31 10月03日 Update

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.

Tags: Data scheme size statistics function that is database structure result application Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Docker MariaDB Redmi Linux