Skip to content

Commit 4ebb1b6

Browse files
authored
feat: update sql solution to lc problem: No.1435 (doocs#1824)
* feat: update sql solution to lc problem: No.1435 * fix: bin
1 parent 9aed9e1 commit 4ebb1b6

File tree

3 files changed

+12
-132
lines changed

3 files changed

+12
-132
lines changed

solution/1400-1499/1435.Create a Session Bar Chart/README.md

+4-44
Original file line numberDiff line numberDiff line change
@@ -70,53 +70,13 @@ Sessions 表:
7070
### **SQL**
7171

7272
```sql
73-
(
74-
SELECT
75-
'[0-5>' AS bin,
76-
SUM(
77-
CASE
78-
WHEN duration / 60 < 5 THEN 1
79-
ELSE 0
80-
END
81-
) AS total
82-
FROM Sessions
83-
)
73+
SELECT '[0-5>' AS bin, count(1) AS total FROM Sessions WHERE duration < 300
8474
UNION
85-
(
86-
SELECT
87-
'[5-10>' AS bin,
88-
SUM(
89-
CASE
90-
WHEN (duration / 60 >= 5 AND duration / 60 < 10) THEN 1
91-
ELSE 0
92-
END
93-
) AS total
94-
FROM Sessions
95-
)
75+
SELECT '[5-10>' AS bin, count(1) AS total FROM Sessions WHERE 300 <= duration AND duration < 600
9676
UNION
97-
(
98-
SELECT
99-
'[10-15>' AS bin,
100-
SUM(
101-
CASE
102-
WHEN (duration / 60 >= 10 AND duration / 60 < 15) THEN 1
103-
ELSE 0
104-
END
105-
) AS total
106-
FROM Sessions
107-
)
77+
SELECT '[10-15>' AS bin, count(1) AS total FROM Sessions WHERE 600 <= duration AND duration < 900
10878
UNION
109-
(
110-
SELECT
111-
'15 or more' AS bin,
112-
SUM(
113-
CASE
114-
WHEN duration / 60 >= 15 THEN 1
115-
ELSE 0
116-
END
117-
) AS total
118-
FROM Sessions
119-
);
79+
SELECT '15 or more' AS bin, count(1) AS total FROM Sessions WHERE 900 <= duration;
12080
```
12181

12282
<!-- tabs:end -->

solution/1400-1499/1435.Create a Session Bar Chart/README_EN.md

+4-44
Original file line numberDiff line numberDiff line change
@@ -65,53 +65,13 @@ For session_id 5 has a duration greater than or equal to 15 minutes.
6565
### **SQL**
6666

6767
```sql
68-
(
69-
SELECT
70-
'[0-5>' AS bin,
71-
SUM(
72-
CASE
73-
WHEN duration / 60 < 5 THEN 1
74-
ELSE 0
75-
END
76-
) AS total
77-
FROM Sessions
78-
)
68+
SELECT '[0-5>' AS bin, count(1) AS total FROM Sessions WHERE duration < 300
7969
UNION
80-
(
81-
SELECT
82-
'[5-10>' AS bin,
83-
SUM(
84-
CASE
85-
WHEN (duration / 60 >= 5 AND duration / 60 < 10) THEN 1
86-
ELSE 0
87-
END
88-
) AS total
89-
FROM Sessions
90-
)
70+
SELECT '[5-10>' AS bin, count(1) AS total FROM Sessions WHERE 300 <= duration AND duration < 600
9171
UNION
92-
(
93-
SELECT
94-
'[10-15>' AS bin,
95-
SUM(
96-
CASE
97-
WHEN (duration / 60 >= 10 AND duration / 60 < 15) THEN 1
98-
ELSE 0
99-
END
100-
) AS total
101-
FROM Sessions
102-
)
72+
SELECT '[10-15>' AS bin, count(1) AS total FROM Sessions WHERE 600 <= duration AND duration < 900
10373
UNION
104-
(
105-
SELECT
106-
'15 or more' AS bin,
107-
SUM(
108-
CASE
109-
WHEN duration / 60 >= 15 THEN 1
110-
ELSE 0
111-
END
112-
) AS total
113-
FROM Sessions
114-
);
74+
SELECT '15 or more' AS bin, count(1) AS total FROM Sessions WHERE 900 <= duration;
11575
```
11676

11777
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,7 @@
1-
(
2-
SELECT
3-
'[0-5>' AS bin,
4-
SUM(
5-
CASE
6-
WHEN duration / 60 < 5 THEN 1
7-
ELSE 0
8-
END
9-
) AS total
10-
FROM Sessions
11-
)
1+
SELECT '[0-5>' AS bin, count(1) AS total FROM Sessions WHERE duration < 300
122
UNION
13-
(
14-
SELECT
15-
'[5-10>' AS bin,
16-
SUM(
17-
CASE
18-
WHEN (duration / 60 >= 5 AND duration / 60 < 10) THEN 1
19-
ELSE 0
20-
END
21-
) AS total
22-
FROM Sessions
23-
)
3+
SELECT '[5-10>' AS bin, count(1) AS total FROM Sessions WHERE 300 <= duration AND duration < 600
244
UNION
25-
(
26-
SELECT
27-
'[10-15>' AS bin,
28-
SUM(
29-
CASE
30-
WHEN (duration / 60 >= 10 AND duration / 60 < 15) THEN 1
31-
ELSE 0
32-
END
33-
) AS total
34-
FROM Sessions
35-
)
5+
SELECT '[10-15>' AS bin, count(1) AS total FROM Sessions WHERE 600 <= duration AND duration < 900
366
UNION
37-
(
38-
SELECT
39-
'15 or more' AS bin,
40-
SUM(
41-
CASE
42-
WHEN duration / 60 >= 15 THEN 1
43-
ELSE 0
44-
END
45-
) AS total
46-
FROM Sessions
47-
);
7+
SELECT '15 or more' AS bin, count(1) AS total FROM Sessions WHERE 900 <= duration;

0 commit comments

Comments
 (0)