FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Leetcode-Solutions/MySQL/active-users.sql at main · rezzcode/Leetcode-Solutions · GitHub
This repository was archived by the owner on Mar 1, 2026. It is now read-only.
rezzcode
/
Leetcode-Solutions
Public archive
Notifications
You must be signed in to change notification settings
Fork
1
Star
5
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Leetcode-Solutions
/
MySQL
/
active-users.sql
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (33 loc) · 899 Bytes
Breadcrumbs
Leetcode-Solutions
/
MySQL
/
active-users.sql
Copy path
File metadata and controls
34 lines (33 loc) · 899 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#
Time: O(nlogn)
#
Space: O(n)
SELECT DISTINCT
r
.
id
,
r
.
name
FROM
(
SELECT
a_l
.
id
,
a_l
.
name
,
@accu :
=
CASE
WHEN
a_l
.
name
=
@prev
AND
DATEDIFF(
a_l
.
login_date
, @login_date)
=
1
THEN @accu
+
1
ELSE
1
END
AS
accu,
@prev :
=
a_l
.
name
AS
prev,
@login_date :
=
a_l
.
login_date
AS
login_date
FROM
(
(
SELECT DISTINCT
a
.
id
,
a
.
name
,
l
.
login_date
FROM
accounts a
LEFT JOIN
logins l
ON
a
.
id
=
l
.
id
ORDER BY
a
.
id
,
a
.
name
,
l
.
login_date
) a_l,
(
SELECT
@accu :
=
0
,
@prev :
=
"
"
,
@login_date :
=
"
"
) init
)
) r
WHERE
r
.
accu
=
5
;
Back
|
FazBrowse Home
|
New Git URL