Skip to content

Commit 8cce10f

Browse files
committed
solve problem 4
1 parent 0ff0253 commit 8cce10f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

MySol/Create Session bar chart.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
把資料庫建起來的SQL
2+
```SQL
3+
CREATE TABLE session_2(
4+
session_id int,
5+
duration int,
6+
PRIMARY KEY (session_id)
7+
);
8+
9+
INSERT INTO session_2 (session_id, duration) VALUES
10+
(1, 30),
11+
(2, 199),
12+
(3, 299),
13+
(4, 580),
14+
(5, 1000);
15+
```
16+
17+
查詢的SQL
18+
```SQL
19+
SELECT
20+
CASE
21+
WHEN duration < 300 THEN "[0-5>"
22+
WHEN duration < 600 THEN "[5-10>"
23+
WHEN duration < 900 THEN "[10-15>"
24+
ELSE "15 or more"
25+
END AS bin, count(*) as count
26+
FROM myjdbc.session_2 group by bin;
27+
```
28+
![alt text](image-4.png)
29+
上面這種做法的問題點就是有出現count為0的狀況,那種`bin`不會被列出來。
30+
另一種做法就是分開做然後再全部UNION起來,如原作者的解答那樣

MySol/image-4.png

2.22 KB
Loading

0 commit comments

Comments
 (0)