SQL queries, select records with specific datatime occurrences (3 per week, 3 days in a row )
Posted by:
andr ptt
Date: January 25, 2023 09:35AM
I'm studying MySQL and I stumbled on some exercises where I got no idea how to approach the problem.
I have 2 Tables:
sys_users containing id username
sys_user_sessions containing id user_id login_tstamp logout_tstamp
I have been asked to query:
All users that login at least 3 times a week in the past month
The most common session durations in 30 min blocks for the past month
Users who logged at least 3 consecutive days in the past 2 months
Link to tables: http s://drive.google.com/file/d/1XNKSMVVfUzPyDXmEnBl-BWUi9O17doTu/view?usp=share_link (remove space between http and s if you wish to download the tables)
What I managed to do currently:
$todayDate = 1639033043;
$oneMonthAgoDate = $todayDate - 2419200;
SELECT * FROM `sys_users`
INNER JOIN sys_user_sessions ON sys_users.id=sys_user_sessions.user_id
WHERE sys_user_sessions.login_tstamp
BETWEEN '" . strval($oneMonthAgoDate) . "'
AND '" . strval($todayDate) . "'
HAVING COUNT(DISTINCT sys_user_sessions.login_tstamp ) >= 3
EXPECTED RESULTS: test_comunic user
Subject
Written By
Posted
SQL queries, select records with specific datatime occurrences (3 per week, 3 days in a row )
January 25, 2023 09:35AM
Sorry, only registered users may post in this forum.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.