FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/MySQL/create-a-session-bar-chart.sql at master · code-cse/LeetCode-Solutions · GitHub
code-cse
/
LeetCode-Solutions
Public
forked from
kamyu104/LeetCode-Solutions
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
MySQL
/
create-a-session-bar-chart.sql
Copy path
More file actions
More file actions
Latest commit
History
History
History
53 lines (51 loc) · 1.1 KB
Breadcrumbs
LeetCode-Solutions
/
MySQL
/
create-a-session-bar-chart.sql
Copy path
File metadata and controls
53 lines (51 loc) · 1.1 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#
Time: O(n)
#
Space: O(1)
SELECT
'
[0-5>
'
AS
bin,
Count
(
1
)
AS
total
FROM
sessions
WHERE
duration
>=
0
AND
duration
<
300
UNION ALL
SELECT
'
[5-10>
'
AS
bin,
Count
(
1
)
AS
total
FROM
sessions
WHERE
duration
>=
300
AND
duration
<
600
UNION ALL
SELECT
'
[10-15>
'
AS
bin,
Count
(
1
)
AS
total
FROM
sessions
WHERE
duration
>=
600
AND
duration
<
900
UNION ALL
SELECT
'
15 or more
'
AS
bin,
Count
(
1
)
AS
total
FROM
sessions
WHERE
duration
>=
900
;
#
Time: O(n)
#
Space: O(n)
SELECT
t2
.
BIN
,
COUNT
(
t1
.
BIN
)
AS
TOTAL
FROM
(
SELECT
CASE
WHEN duration
/
60
BETWEEN
0
AND
5
THEN
"
[0-5>
"
WHEN duration
/
60
BETWEEN
5
AND
10
THEN
"
[5-10>
"
WHEN duration
/
60
BETWEEN
10
AND
15
THEN
"
[10-15>
"
WHEN duration
/
60
>=
15
THEN
"
15 or more
"
ELSE
NULL
END
AS
BIN
FROM
Sessions
) t1
RIGHT JOIN
(
SELECT
"
[0-5>
"
AS
BIN
UNION ALL
SELECT
"
[5-10>
"
AS
BIN
UNION ALL
SELECT
"
[10-15>
"
AS
BIN
UNION ALL
SELECT
"
15 or more
"
AS
BIN
) t2
ON
t1
.
bin
=
t2
.
bin
GROUP BY
t2
.
bin
ORDER BY
NULL
;
Back
|
FazBrowse Home
|
New Git URL