SQL279. 实习广场投递简历分析(二)
描述
id | job | date | num |
1 | C++ | 2025-01-02 | 53 |
2 | Python | 2025-01-02 | 23 |
3 | Java | 2025-01-02 | 12 |
4 | C++ | 2025-01-03 | 54 |
5 | Python | 2025-01-03 | 43 |
6 | Java | 2025-01-03 | 41 |
7 | Java | 2025-02-03 | 24 |
8 | C++ | 2025-02-03 | 23 |
9 | Python | 2025-02-03 | 34 |
10 | Java | 2025-02-04 | 42 |
11 | C++ | 2025-02-04 | 45 |
12 | Python | 2025-02-04 | 59 |
13 | Python | 2025-03-04 | 54 |
14 | C++ | 2025-03-04 | 65 |
15 | Java | 2025-03-04 | 92 |
16 | Python | 2025-03-05 | 34 |
17 | C++ | 2025-03-05 | 34 |
18 | Java | 2025-03-05 | 34 |
19 | Python | 2026-01-04 | 230 |
20 | C++ | 2026-02-06 | 231 |
job | mon | cnt |
Java | 2025-03 | 126 |
C++ | 2025-03 | 99 |
Python | 2025-03 | 88 |
Python | 2025-02 | 93 |
C++ | 2025-02 | 68 |
Java | 2025-02 | 66 |
C++ | 2025-01 | 107 |
Python | 2025-01 | 66 |
Java | 2025-01 | 53 |
示例1
输入:
drop table if exists resume_info; CREATE TABLE resume_info ( id int(4) NOT NULL, job varchar(64) NOT NULL, date date NOT NULL, num int(11) NOT NULL, PRIMARY KEY (id)); INSERT INTO resume_info VALUES (1,'C++','2025-01-02',53), (2,'Python','2025-01-02',23), (3,'Java','2025-01-02',12), (4,'C++','2025-01-03',54), (5,'Python','2025-01-03',43), (6,'Java','2025-01-03',41), (7,'Java','2025-02-03',24), (8,'C++','2025-02-03',23), (9,'Python','2025-02-03',34), (10,'Java','2025-02-04',42), (11,'C++','2025-02-04',45), (12,'Python','2025-02-04',59), (13,'Python','2025-03-04',54), (14,'C++','2025-03-04',65), (15,'Java','2025-03-04',92), (16,'Python','2025-03-05',34), (17,'C++','2025-03-05',34), (18,'Java','2025-03-05',34), (19,'Python','2026-01-04',230), (20,'C++','2026-02-06',231);
输出:
Java|2025-03|126 C++|2025-03|99 Python|2025-03|88 Python|2025-02|93 C++|2025-02|68 Java|2025-02|66 C++|2025-01|107 Python|2025-01|66 Java|2025-01|53
Sqlite 解法, 执行用时: 11ms, 内存消耗: 3304KB, 提交时间: 2021-07-27
-- 按月统计数量并排序 select job,substr(date,1,7) as mon,sum(num) as cnt from resume_info where date like '2025%' -- 符合最左前缀匹配原则,也走索引 group by job,mon order by mon desc,cnt desc
Sqlite 解法, 执行用时: 11ms, 内存消耗: 3368KB, 提交时间: 2021-09-07
select job, substr(date ,1,7) mon,sum(num) cnt from resume_info where date like '%2025%' group by mon,job order by mon desc,cnt desc
Sqlite 解法, 执行用时: 11ms, 内存消耗: 3372KB, 提交时间: 2022-02-21
select job, substr(date,0,8) as mon , sum(num) as cnt from resume_info where date >= '2025-01-01' and date <'2026-01-01' group by job, mon order by mon desc , cnt desc
Sqlite 解法, 执行用时: 11ms, 内存消耗: 3372KB, 提交时间: 2021-12-14
select job, strftime("%Y-%m", date) mon, sum(num) cnt from resume_info where date like '2025%' group by job, mon order by mon desc, cnt desc
Sqlite 解法, 执行用时: 11ms, 内存消耗: 3376KB, 提交时间: 2021-09-18
select job, strftime('%Y-%m', date) mon, sum(num) cnt from resume_info where date like '2025%' group by job, mon order by mon desc, cnt desc;