How does one count the number of online users per hour ?, Count the number of online users

Source: Internet
Author: User

How does one count the number of online users per hour ?, Count the number of online users

The system has a table that records user logon and logout logs. Now, the number of online users is measured in an hour. This is a mathematical problem.

Case 1:

| ___________ One hour ____________ |

<= Logon time logout time <=

Case 2:

| ___________ One hour ____________ |

Logon Time <logout time

Case 3:

| ___________ One hour ____________ |

Logon Time <= logout time <=

Case 4:

| ___________ One hour ____________ |

<= Logon time <logout time


With dd as (-- simulate a 24-hour period

SELECT (trunc (to_date ('1970-02-09 ', 'yyyy-mm-dd') + (LEVEL-1)/24) one_hour_1,
(Trunc (to_date ('1970-02-09 ', 'yyyy-mm-dd') + LEVEL/24) one_hour_2
FROM dual
Connect by level <= 24
)
SELECT dd. one_hour_1, COUNT (1)
FROM log_user_login d,
Dd
WHERE (d. login_time> = dd. one_hour_1 AND d. exit_time <= dd. one_hour_2)
OR (d. login_time <dd. one_hour_1 AND d. exit_time BETWEEN dd. one_hour_1 AND dd. one_hour_2)
OR (d. login_time BETWEEN dd. one_hour_1 AND dd. one_hour_2 AND d. exit_time> dd. one_hour_2)
OR (d. login_time <dd. one_hour_1 AND d. exit_time> dd. one_hour_2)
Group by dd. one_hour_1
Order by dd. one_hour_1;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.