diff --git a/docs/about-the-author/zhishixingqiu-two-years.md b/docs/about-the-author/zhishixingqiu-two-years.md index 1ab2b6bb..c3bdc726 100644 --- a/docs/about-the-author/zhishixingqiu-two-years.md +++ b/docs/about-the-author/zhishixingqiu-two-years.md @@ -143,7 +143,7 @@ JavaGuide 知识星球优质主题汇总传送门:tj, i1` 时 `C[i] = C[i] + C[i-1]`; 5. 创建结果数组 `R`,长度和原始数组一样。 -6. **从后向前**遍历原始数组 `A` 中的元素 `A[i]`,使用 `A[i]` 减去最小值 `min` 作为索引,在计数数组 `C` 中找到对应的值 `C[A[i]-min]`,`C[A[i]-min]-1` 就是 `A[i]` 在结果数组 `R` 中的位置,做完上述这些操作,将 `count[A[i]-min]` 减小 1。 +6. **从后向前**遍历原始数组 `A` 中的元素 `A[i]`,使用 `A[i]` 减去最小值 `min` 作为索引,在计数数组 `C` 中找到对应的值 `C[A[i] - min]`,`C[A[i] - min] - 1` 就是 `A[i]` 在结果数组 `R` 中的位置,做完上述这些操作,将 `count[A[i] - min]` 减小 1。 ### 图解算法 @@ -567,10 +567,10 @@ public static int[] countingSort(int[] arr) { ## 算法分析 -当输入的元素是 `n` 个 `0` 到 `k` 之间的整数时,它的运行时间是 `O(n+k)`。计数排序不是比较排序,排序的速度快于任何比较排序算法。由于用来计数的数组 `C` 的长度取决于待排序数组中数据的范围(等于待排序数组的**最大值与最小值的差加上 1**),这使得计数排序对于数据范围很大的数组,需要大量额外内存空间。 +当输入的元素是 `n` 个 `0` 到 `k` 之间的整数时,它的运行时间是 $O(n+k)$。计数排序不是比较排序,排序的速度快于任何比较排序算法。由于用来计数的数组 `C` 的长度取决于待排序数组中数据的范围(等于待排序数组的**最大值与最小值的差加上 1**),这使得计数排序对于数据范围很大的数组,需要大量额外内存空间。 - **稳定性**:稳定 -- **时间复杂度**:最佳:`O(n+k)` 最差:`O(n+k)` 平均:`O(n+k)` +- **时间复杂度**:最佳:$O(n+k)$ 最差:$O(n+k)$ 平均:$O(n+k)$ - **空间复杂度**:`O(k)` ## 桶排序 (Bucket Sort) @@ -653,22 +653,22 @@ public static List bucketSort(List arr, int bucket_size) { ### 算法分析 - **稳定性**:稳定 -- **时间复杂度**:最佳:`O(n+k)` 最差:`O(n²)` 平均:`O(n+k)` -- **空间复杂度**:`O(n+k)` +- **时间复杂度**:最佳:$O(n+k)$ 最差:$O(n^2)$ 平均:$O(n+k)$ +- **空间复杂度**:$O(n+k)$ ## 基数排序 (Radix Sort) -基数排序也是非比较的排序算法,对元素中的每一位数字进行排序,从最低位开始排序,复杂度为 `O(n×k)`,`n` 为数组长度,`k` 为数组中元素的最大的位数; +基数排序也是非比较的排序算法,对元素中的每一位数字进行排序,从最低位开始排序,复杂度为 $O(n×k)$,$n$ 为数组长度,$k$ 为数组中元素的最大的位数; 基数排序是按照低位先排序,然后收集;再按照高位排序,然后再收集;依次类推,直到最高位。有时候有些属性是有优先级顺序的,先按低优先级排序,再按高优先级排序。最后的次序就是高优先级高的在前,高优先级相同的低优先级高的在前。基数排序基于分别排序,分别收集,所以是稳定的。 ### 算法步骤 -1. 取得数组中的最大数,并取得位数,即为迭代次数 `N`(例如:数组中最大数值为 1000,则 `N=4`); +1. 取得数组中的最大数,并取得位数,即为迭代次数 $N$(例如:数组中最大数值为 1000,则 $N=4$); 2. `A` 为原始数组,从最低位开始取每个位组成 `radix` 数组; 3. 对 `radix` 进行计数排序(利用计数排序适用于小范围数的特点); 4. 将 `radix` 依次赋值给原数组; -5. 重复 2~4 步骤 `N` 次 +5. 重复 2~4 步骤 $N$ 次 ### 图解算法 @@ -721,8 +721,8 @@ public static int[] radixSort(int[] arr) { ### 算法分析 - **稳定性**:稳定 -- **时间复杂度**:最佳:`O(n×k)` 最差:`O(n×k)` 平均:`O(n×k)` -- **空间复杂度**:`O(n+k)` +- **时间复杂度**:最佳:$O(n×k)$ 最差:$O(n×k)$ 平均:$O(n×k)$ +- **空间复杂度**:$O(n+k)$ **基数排序 vs 计数排序 vs 桶排序** diff --git a/docs/cs-basics/algorithms/linkedlist-algorithm-problems.md b/docs/cs-basics/algorithms/linkedlist-algorithm-problems.md index 48a071d3..280d4a06 100644 --- a/docs/cs-basics/algorithms/linkedlist-algorithm-problems.md +++ b/docs/cs-basics/algorithms/linkedlist-algorithm-problems.md @@ -384,4 +384,4 @@ public class Solution { } ``` - \ No newline at end of file + diff --git a/docs/cs-basics/algorithms/string-algorithm-problems.md b/docs/cs-basics/algorithms/string-algorithm-problems.md index f8f493e3..a8d23bae 100644 --- a/docs/cs-basics/algorithms/string-algorithm-problems.md +++ b/docs/cs-basics/algorithms/string-algorithm-problems.md @@ -460,4 +460,4 @@ public class Main { ``` - \ No newline at end of file + diff --git a/docs/cs-basics/algorithms/the-sword-refers-to-offer.md b/docs/cs-basics/algorithms/the-sword-refers-to-offer.md index 596d6447..0e7b32c1 100644 --- a/docs/cs-basics/algorithms/the-sword-refers-to-offer.md +++ b/docs/cs-basics/algorithms/the-sword-refers-to-offer.md @@ -682,4 +682,4 @@ public class Solution { } ``` - \ No newline at end of file + diff --git a/docs/cs-basics/data-structure/bloom-filter.md b/docs/cs-basics/data-structure/bloom-filter.md index 73570866..06662ed2 100644 --- a/docs/cs-basics/data-structure/bloom-filter.md +++ b/docs/cs-basics/data-structure/bloom-filter.md @@ -309,4 +309,4 @@ root@21396d02c252:/data# redis-cli (integer) 0 ``` - \ No newline at end of file + diff --git a/docs/cs-basics/data-structure/graph.md b/docs/cs-basics/data-structure/graph.md index 38065c6a..e9860c24 100644 --- a/docs/cs-basics/data-structure/graph.md +++ b/docs/cs-basics/data-structure/graph.md @@ -157,4 +157,4 @@ tag: ![深度优先搜索6](https://oss.javaguide.cn/github/javaguide/cs-basics/data-structure/depth-first-search6.png) - \ No newline at end of file + diff --git a/docs/cs-basics/data-structure/heap.md b/docs/cs-basics/data-structure/heap.md index 8521084f..5de2e5f2 100644 --- a/docs/cs-basics/data-structure/heap.md +++ b/docs/cs-basics/data-structure/heap.md @@ -199,4 +199,4 @@ tag: 堆排序完成! - \ No newline at end of file + diff --git a/docs/cs-basics/data-structure/linear-data-structure.md b/docs/cs-basics/data-structure/linear-data-structure.md index a92e4059..154fb50e 100644 --- a/docs/cs-basics/data-structure/linear-data-structure.md +++ b/docs/cs-basics/data-structure/linear-data-structure.md @@ -328,4 +328,4 @@ myStack.pop();//报错:java.lang.IllegalArgumentException: Stack is empty. - 消息队列 - 等等…… - \ No newline at end of file + diff --git a/docs/cs-basics/data-structure/red-black-tree.md b/docs/cs-basics/data-structure/red-black-tree.md index ed63c679..20d60e62 100644 --- a/docs/cs-basics/data-structure/red-black-tree.md +++ b/docs/cs-basics/data-structure/red-black-tree.md @@ -20,4 +20,4 @@ tag: **相关阅读**:[《红黑树深入剖析及 Java 实现》](https://zhuanlan.zhihu.com/p/24367771)(美团点评技术团队) - \ No newline at end of file + diff --git a/docs/cs-basics/data-structure/tree.md b/docs/cs-basics/data-structure/tree.md index d8fe1c10..9727359c 100644 --- a/docs/cs-basics/data-structure/tree.md +++ b/docs/cs-basics/data-structure/tree.md @@ -182,4 +182,4 @@ public void postOrder(TreeNode root){ } ``` - \ No newline at end of file + diff --git a/docs/cs-basics/network/application-layer-protocol.md b/docs/cs-basics/network/application-layer-protocol.md index 044c0196..09a7958f 100644 --- a/docs/cs-basics/network/application-layer-protocol.md +++ b/docs/cs-basics/network/application-layer-protocol.md @@ -112,4 +112,4 @@ DNS(Domain Name System,域名管理系统)基于 UDP 协议,用于解决 - 《计算机网络自顶向下方法》(第七版) - RTP 协议介绍:https://mthli.xyz/rtp-introduction/ - \ No newline at end of file + diff --git a/docs/cs-basics/network/arp.md b/docs/cs-basics/network/arp.md index 85264d88..b0bb5f26 100644 --- a/docs/cs-basics/network/arp.md +++ b/docs/cs-basics/network/arp.md @@ -102,4 +102,4 @@ ARP 的工作原理将分两种场景讨论: ![](./images/arp/arp_different_lan.png) - \ No newline at end of file + diff --git a/docs/cs-basics/network/dns.md b/docs/cs-basics/network/dns.md index 0e88b393..eba55083 100644 --- a/docs/cs-basics/network/dns.md +++ b/docs/cs-basics/network/dns.md @@ -101,4 +101,4 @@ foo.example.com. A 192.0.2.23 - DNS Message Resource Record Field Formats:http://www.tcpipguide.com/free/t_DNSMessageResourceRecordFieldFormats-2.htm - Understanding Different Types of Record in DNS Server:https://www.mustbegeek.com/understanding-different-types-of-record-in-dns-server/ - \ No newline at end of file + diff --git a/docs/cs-basics/network/http-status-codes.md b/docs/cs-basics/network/http-status-codes.md index 269585b8..ca4e2a10 100644 --- a/docs/cs-basics/network/http-status-codes.md +++ b/docs/cs-basics/network/http-status-codes.md @@ -69,4 +69,4 @@ HTTP 状态码用于描述 HTTP 请求的结果,比如 2xx 就代表请求被 - https://en.wikipedia.org/wiki/List_of_HTTP_status_codes - https://segmentfault.com/a/1190000018264501 - \ No newline at end of file + diff --git a/docs/cs-basics/network/http-vs-https.md b/docs/cs-basics/network/http-vs-https.md index aca58035..71c224f1 100644 --- a/docs/cs-basics/network/http-vs-https.md +++ b/docs/cs-basics/network/http-vs-https.md @@ -139,4 +139,4 @@ SSL/TLS 介绍到这里,了解信息安全的朋友又会想到一个安全隐 - **URL 前缀**:HTTP 的 URL 前缀是 `http://`,HTTPS 的 URL 前缀是 `https://`。 - **安全性和资源消耗**:HTTP 协议运行在 TCP 之上,所有传输的内容都是明文,客户端和服务器端都无法验证对方的身份。HTTPS 是运行在 SSL/TLS 之上的 HTTP 协议,SSL/TLS 运行在 TCP 之上。所有传输的内容都经过加密,加密采用对称加密,但对称加密的密钥用服务器方的证书进行了非对称加密。所以说,HTTP 安全性没有 HTTPS 高,但是 HTTPS 比 HTTP 耗费更多服务器资源。 - \ No newline at end of file + diff --git a/docs/cs-basics/network/http1.0-vs-http1.1.md b/docs/cs-basics/network/http1.0-vs-http1.1.md index 6f177ab3..41931829 100644 --- a/docs/cs-basics/network/http1.0-vs-http1.1.md +++ b/docs/cs-basics/network/http1.0-vs-http1.1.md @@ -104,4 +104,4 @@ HTTP/1.0 包含了`Content-Encoding`头部,对消息进行端到端编码。HT [Key differences between HTTP/1.0 and HTTP/1.1](http://www.ra.ethz.ch/cdstore/www8/data/2136/pdf/pd1.pdf) - \ No newline at end of file + diff --git a/docs/cs-basics/network/nat.md b/docs/cs-basics/network/nat.md index 52f6740c..5634ba07 100644 --- a/docs/cs-basics/network/nat.md +++ b/docs/cs-basics/network/nat.md @@ -57,4 +57,4 @@ SOHO 子网的“代理人”,也就是和外界的窗口,通常由路由器 然而,NAT 协议由于其独特性,存在着一些争议。比如,可能你已经注意到了,**NAT 协议在 LAN 以外,标识一个内部主机时,使用的是端口号,因为 IP 地址都是相同的。**这种将端口号作为主机寻址的行为,可能会引发一些误会。此外,路由器作为网络层的设备,修改了传输层的分组内容(修改了源 IP 地址和端口号),同样是不规范的行为。但是,尽管如此,NAT 协议作为 IPv4 时代的产物,极大地方便了一些本来棘手的问题,一直被沿用至今。 - \ No newline at end of file + diff --git a/docs/cs-basics/network/network-attack-means.md b/docs/cs-basics/network/network-attack-means.md index 1be485f6..9117a4ad 100644 --- a/docs/cs-basics/network/network-attack-means.md +++ b/docs/cs-basics/network/network-attack-means.md @@ -467,4 +467,4 @@ CDN 加速,我们可以这么理解:为了减少流氓骚扰,我干脆将 - 什么是 IP 欺骗?:https://www.cloudflare.com/zh-cn/learning/ddos/glossary/ip-spoofing/ - 什么是 DNS 洪水?| DNS 洪水 DDoS 攻击:https://www.cloudflare.com/zh-cn/learning/ddos/dns-flood-ddos-attack/ - \ No newline at end of file + diff --git a/docs/cs-basics/network/osi-and-tcp-ip-model.md b/docs/cs-basics/network/osi-and-tcp-ip-model.md index e582470d..424d8375 100644 --- a/docs/cs-basics/network/osi-and-tcp-ip-model.md +++ b/docs/cs-basics/network/osi-and-tcp-ip-model.md @@ -192,4 +192,4 @@ OSI 七层模型虽然失败了,但是却提供了很多不错的理论基础 - TCP/IP model vs OSI model:https://fiberbit.com.tw/tcpip-model-vs-osi-model/ - Data Encapsulation and the TCP/IP Protocol Stack:https://docs.oracle.com/cd/E19683-01/806-4075/ipov-32/index.html - \ No newline at end of file + diff --git a/docs/cs-basics/network/other-network-questions.md b/docs/cs-basics/network/other-network-questions.md index ae614afa..5ee30f68 100644 --- a/docs/cs-basics/network/other-network-questions.md +++ b/docs/cs-basics/network/other-network-questions.md @@ -340,4 +340,4 @@ DNS 服务器自底向上可以依次分为以下几个层级(所有 DNS 服务 - HTTP1、HTTP2、HTTP3: - 如何看待 HTTP/3 ? - 车小胖的回答 - 知乎: - \ No newline at end of file + diff --git a/docs/cs-basics/network/other-network-questions2.md b/docs/cs-basics/network/other-network-questions2.md index 3d827796..d7f6871b 100644 --- a/docs/cs-basics/network/other-network-questions2.md +++ b/docs/cs-basics/network/other-network-questions2.md @@ -187,4 +187,4 @@ ARP 协议,全称 **地址解析协议(Address Resolution Protocol)**, - 什么是 Internet 协议(IP)?: - What Is NAT and What Are the Benefits of NAT Firewalls?: - \ No newline at end of file + diff --git a/docs/cs-basics/network/tcp-connection-and-disconnection.md b/docs/cs-basics/network/tcp-connection-and-disconnection.md index b97a718a..cc09bdce 100644 --- a/docs/cs-basics/network/tcp-connection-and-disconnection.md +++ b/docs/cs-basics/network/tcp-connection-and-disconnection.md @@ -83,4 +83,4 @@ TCP 是全双工通信,可以双向传输数据。任何一方都可以在数 - TCP and UDP Tutorial:https://www.9tut.com/tcp-and-udp-tutorial - \ No newline at end of file + diff --git a/docs/cs-basics/network/tcp-reliability-guarantee.md b/docs/cs-basics/network/tcp-reliability-guarantee.md index ba558b59..bd64a5ae 100644 --- a/docs/cs-basics/network/tcp-reliability-guarantee.md +++ b/docs/cs-basics/network/tcp-reliability-guarantee.md @@ -115,4 +115,4 @@ ARQ 包括停止等待 ARQ 协议和连续 ARQ 协议。 6. TCP 流量控制(Flow Control):https://notfalse.net/24/tcp-flow-control 7. TCP 之滑动窗口原理 : https://cloud.tencent.com/developer/article/1857363 - \ No newline at end of file + diff --git a/docs/cs-basics/operating-system/linux-intro.md b/docs/cs-basics/operating-system/linux-intro.md index f7b7c50c..ce433c17 100644 --- a/docs/cs-basics/operating-system/linux-intro.md +++ b/docs/cs-basics/operating-system/linux-intro.md @@ -428,4 +428,4 @@ vim ~/.bash_profile source /etc/profile ``` - \ No newline at end of file + diff --git a/docs/cs-basics/operating-system/operating-system-basic-questions-01.md b/docs/cs-basics/operating-system/operating-system-basic-questions-01.md index 89e79a95..de1a9073 100644 --- a/docs/cs-basics/operating-system/operating-system-basic-questions-01.md +++ b/docs/cs-basics/operating-system/operating-system-basic-questions-01.md @@ -458,4 +458,4 @@ Thread[线程 2,5,main]waiting get resource1 - 从根上理解用户态与内核态:https://juejin.cn/post/6923863670132850701 - 什么是僵尸进程与孤儿进程:https://blog.csdn.net/a745233700/article/details/120715371 - \ No newline at end of file + diff --git a/docs/cs-basics/operating-system/operating-system-basic-questions-02.md b/docs/cs-basics/operating-system/operating-system-basic-questions-02.md index 03845317..a7df8275 100644 --- a/docs/cs-basics/operating-system/operating-system-basic-questions-02.md +++ b/docs/cs-basics/operating-system/operating-system-basic-questions-02.md @@ -410,4 +410,4 @@ LRU 算法是实际使用中应用的比较多,也被认为是最接近 OPT - 程序员的自我修养(七):内存缺页错误:https://liam.page/2017/09/01/page-fault/ - 虚拟内存的那点事儿:https://juejin.cn/post/6844903507594575886 - \ No newline at end of file + diff --git a/docs/cs-basics/operating-system/shell-intro.md b/docs/cs-basics/operating-system/shell-intro.md index 2b4d13d9..38e3d824 100644 --- a/docs/cs-basics/operating-system/shell-intro.md +++ b/docs/cs-basics/operating-system/shell-intro.md @@ -533,4 +533,4 @@ funWithParam 1 2 3 4 5 6 7 8 9 34 73 作为一个字符串输出所有参数 1 2 3 4 5 6 7 8 9 34 73 ! ``` - \ No newline at end of file + diff --git a/docs/database/character-set.md b/docs/database/character-set.md index 4851035c..3c2d008d 100644 --- a/docs/database/character-set.md +++ b/docs/database/character-set.md @@ -324,4 +324,4 @@ Incorrect string value: '\xF0\x9F\x98\x98\xF0\x9F...' for column 'name' at row 1 - MySQL5.7 文档: - MySQL Connector/J 文档: - \ No newline at end of file + diff --git a/docs/database/elasticsearch/elasticsearch-questions-01.md b/docs/database/elasticsearch/elasticsearch-questions-01.md index 743e94ec..fe6daa69 100644 --- a/docs/database/elasticsearch/elasticsearch-questions-01.md +++ b/docs/database/elasticsearch/elasticsearch-questions-01.md @@ -12,4 +12,4 @@ tag: - \ No newline at end of file + diff --git a/docs/database/mongodb/mongodb-questions-01.md b/docs/database/mongodb/mongodb-questions-01.md index 4083da7f..81ed0139 100644 --- a/docs/database/mongodb/mongodb-questions-01.md +++ b/docs/database/mongodb/mongodb-questions-01.md @@ -283,4 +283,4 @@ WiredTiger 日志也会被压缩,默认使用的也是 Snappy 压缩算法。 - WiredTiger Storage Engine - MongoDB 官方文档: - WiredTiger 存储引擎之一:基础数据结构分析: - \ No newline at end of file + diff --git a/docs/database/mongodb/mongodb-questions-02.md b/docs/database/mongodb/mongodb-questions-02.md index 0ccd54a3..dcd90d72 100644 --- a/docs/database/mongodb/mongodb-questions-02.md +++ b/docs/database/mongodb/mongodb-questions-02.md @@ -272,4 +272,4 @@ Rebalance 操作是比较耗费系统资源的,我们可以通过在业务低 - MongoDB 分片集群介绍 - 阿里云文档: - 分片集群使用注意事项 - - 腾讯云文档: - \ No newline at end of file + diff --git a/docs/database/mysql/a-thousand-lines-of-mysql-study-notes.md b/docs/database/mysql/a-thousand-lines-of-mysql-study-notes.md index 3daf6f70..b3467c98 100644 --- a/docs/database/mysql/a-thousand-lines-of-mysql-study-notes.md +++ b/docs/database/mysql/a-thousand-lines-of-mysql-study-notes.md @@ -954,4 +954,4 @@ OPTIMIZE [LOCAL | NO_WRITE_TO_BINLOG] TABLE tbl_name [, tbl_name] ... 7. 清除已有语句:\c ``` - \ No newline at end of file + diff --git a/docs/database/mysql/how-sql-executed-in-mysql.md b/docs/database/mysql/how-sql-executed-in-mysql.md index de976312..d9f1d07d 100644 --- a/docs/database/mysql/how-sql-executed-in-mysql.md +++ b/docs/database/mysql/how-sql-executed-in-mysql.md @@ -134,4 +134,4 @@ update tb_student A set A.age='19' where A.name=' 张三 '; - 《MySQL 实战 45 讲》 - MySQL 5.6 参考手册: - \ No newline at end of file + diff --git a/docs/database/mysql/innodb-implementation-of-mvcc.md b/docs/database/mysql/innodb-implementation-of-mvcc.md index d37e7088..a2e19998 100644 --- a/docs/database/mysql/innodb-implementation-of-mvcc.md +++ b/docs/database/mysql/innodb-implementation-of-mvcc.md @@ -256,4 +256,4 @@ private: - [MySQL 事务与 MVCC 如何实现的隔离级别](https://blog.csdn.net/qq_35190492/article/details/109044141) - [InnoDB 事务分析-MVCC](https://leviathan.vip/2019/03/20/InnoDB%E7%9A%84%E4%BA%8B%E5%8A%A1%E5%88%86%E6%9E%90-MVCC/) - \ No newline at end of file + diff --git a/docs/database/mysql/mysql-auto-increment-primary-key-continuous.md b/docs/database/mysql/mysql-auto-increment-primary-key-continuous.md index 0ae82c2d..f069f426 100644 --- a/docs/database/mysql/mysql-auto-increment-primary-key-continuous.md +++ b/docs/database/mysql/mysql-auto-increment-primary-key-continuous.md @@ -218,4 +218,4 @@ tag: 3. 事务回滚 4. 批量插入(如 `insert...select` 语句) - \ No newline at end of file + diff --git a/docs/database/mysql/mysql-high-performance-optimization-specification-recommendations.md b/docs/database/mysql/mysql-high-performance-optimization-specification-recommendations.md index 36df01e5..dc6a49fc 100644 --- a/docs/database/mysql/mysql-high-performance-optimization-specification-recommendations.md +++ b/docs/database/mysql/mysql-high-performance-optimization-specification-recommendations.md @@ -140,9 +140,9 @@ MySQL 内存临时表不支持 TEXT、BLOB 这样的大数据类型,如果查 | 类型 | 存储空间 | 日期格式 | 日期范围 | 是否带时区信息 | | ------------ | -------- | ------------------------------ | ------------------------------------------------------------ | -------------- | -| DATETIME | 5~8 字节 | YYYY-MM-DD hh:mm:ss[.fraction] | 1000-01-01 00:00:00[.000000] ~ 9999-12-31 23:59:59[.999999] | 否 | -| TIMESTAMP | 4~7 字节 | YYYY-MM-DD hh:mm:ss[.fraction] | 1970-01-01 00:00:01[.000000] ~ 2038-01-19 03:14:07[.999999] | 是 | -| 数值型时间戳 | 4 字节 | 全数字如 1578707612 | 1970-01-01 00:00:01 之后的时间 | 否 | +| DATETIME | 5~8 字节 | YYYY-MM-DD hh:mm:ss[.fraction] | 1000-01-01 00:00:00[.000000] ~ 9999-12-31 23:59:59[.999999] | 否 | +| TIMESTAMP | 4~7 字节 | YYYY-MM-DD hh:mm:ss[.fraction] | 1970-01-01 00:00:01[.000000] ~ 2038-01-19 03:14:07[.999999] | 是 | +| 数值型时间戳 | 4 字节 | 全数字如 1578707612 | 1970-01-01 00:00:01 之后的时间 | 否 | MySQL 时间类型选择的详细介绍请看这篇:[MySQL 时间类型数据存储建议](https://javaguide.cn/database/mysql/some-thoughts-on-database-storage-time.html)。 @@ -386,4 +386,4 @@ pt-online-schema-change 它会首先建立一个与原表结构相同的新表 - [技术同学必会的 MySQL 设计规约,都是惨痛的教训 - 阿里开发者](https://mp.weixin.qq.com/s/XC8e5iuQtfsrEOERffEZ-Q) - [聊聊数据库建表的 15 个小技巧](https://mp.weixin.qq.com/s/NM-aHaW6TXrnO6la6Jfl5A) - \ No newline at end of file + diff --git a/docs/database/mysql/mysql-index.md b/docs/database/mysql/mysql-index.md index 99fa3694..a842db84 100644 --- a/docs/database/mysql/mysql-index.md +++ b/docs/database/mysql/mysql-index.md @@ -449,4 +449,4 @@ mysql> EXPLAIN SELECT `score`,`name` FROM `cus_order` ORDER BY `score` DESC; 篇幅问题,我这里只是简单介绍了一下 MySQL 执行计划,详细介绍请看:[MySQL 执行计划分析](./mysql-query-execution-plan.md)这篇文章。 - \ No newline at end of file + diff --git a/docs/database/mysql/mysql-logs.md b/docs/database/mysql/mysql-logs.md index 0848b734..49a9da11 100644 --- a/docs/database/mysql/mysql-logs.md +++ b/docs/database/mysql/mysql-logs.md @@ -339,4 +339,4 @@ MySQL InnoDB 引擎使用 **redo log(重做日志)** 保证事务的**持久性* - 《MySQL 是怎样运行的:从根儿上理解 MySQL》 - 《MySQL 技术 Innodb 存储引擎》 - \ No newline at end of file + diff --git a/docs/database/mysql/mysql-query-cache.md b/docs/database/mysql/mysql-query-cache.md index 58a88a82..cdc49b2c 100644 --- a/docs/database/mysql/mysql-query-cache.md +++ b/docs/database/mysql/mysql-query-cache.md @@ -205,4 +205,4 @@ MySQL 中的查询缓存虽然能够提升数据库的查询性能,但是查 - RDS MySQL 查询缓存(Query Cache)的设置和使用 - 阿里元云数据库 RDS 文档: - 8.10.3 The MySQL Query Cache - MySQL 官方文档: - \ No newline at end of file + diff --git a/docs/database/mysql/mysql-questions-01.md b/docs/database/mysql/mysql-questions-01.md index 1a9fe9bf..1324eb80 100644 --- a/docs/database/mysql/mysql-questions-01.md +++ b/docs/database/mysql/mysql-questions-01.md @@ -839,4 +839,4 @@ mysql> EXPLAIN SELECT `score`,`name` FROM `cus_order` ORDER BY `score` DESC; - 深入剖析 MySQL 自增锁: - 在数据库中不可重复读和幻读到底应该怎么分?: - \ No newline at end of file + diff --git a/docs/database/mysql/some-thoughts-on-database-storage-time.md b/docs/database/mysql/some-thoughts-on-database-storage-time.md index 9f957375..75329434 100644 --- a/docs/database/mysql/some-thoughts-on-database-storage-time.md +++ b/docs/database/mysql/some-thoughts-on-database-storage-time.md @@ -163,9 +163,8 @@ MySQL 中时间到底怎么存储才好?Datetime?Timestamp?还是数值时间 | 类型 | 存储空间 | 日期格式 | 日期范围 | 是否带时区信息 | | ------------ | -------- | ------------------------------ | ------------------------------------------------------------ | -------------- | -| DATETIME | 5~8 字节 | YYYY-MM-DD hh:mm:ss[.fraction] | 1000-01-01 00:00:00[.000000] ~ 9999-12-31 23:59:59[.999999] | 否 | -| TIMESTAMP | 4~7 字节 | YYYY-MM-DD hh:mm:ss[.fraction] | 1970-01-01 00:00:01[.000000] ~ 2038-01-19 03:14:07[.999999] | 是 | -| 数值型时间戳 | 4 字节 | 全数字如 1578707612 | 1970-01-01 00:00:01 之后的时间 | 否 | +| DATETIME | 5~8 字节 | YYYY-MM-DD hh:mm:ss[.fraction] | 1000-01-01 00:00:00[.000000] ~ 9999-12-31 23:59:59[.999999] | 否 | +| TIMESTAMP | 4~7 字节 | YYYY-MM-DD hh:mm:ss[.fraction] | 1970-01-01 00:00:01[.000000] ~ 2038-01-19 03:14:07[.999999] | 是 | +| 数值型时间戳 | 4 字节 | 全数字如 1578707612 | 1970-01-01 00:00:01 之后的时间 | 否 | - - \ No newline at end of file + diff --git a/docs/database/mysql/transaction-isolation-level.md b/docs/database/mysql/transaction-isolation-level.md index 430204b7..52ad40f4 100644 --- a/docs/database/mysql/transaction-isolation-level.md +++ b/docs/database/mysql/transaction-isolation-level.md @@ -112,4 +112,4 @@ SQL 脚本 1 在第一次查询工资为 500 的记录时只有一条,SQL 脚 - [Mysql 锁:灵魂七拷问](https://tech.youzan.com/seven-questions-about-the-lock-of-MySQL/) - [Innodb 中的事务隔离级别和锁的关系](https://tech.meituan.com/2014/08/20/innodb-lock.html) - \ No newline at end of file + diff --git a/docs/database/nosql.md b/docs/database/nosql.md index 719f4dfd..d5ca5969 100644 --- a/docs/database/nosql.md +++ b/docs/database/nosql.md @@ -58,4 +58,4 @@ NoSQL 数据库主要可以分为下面四种类型: - 什么是 NoSQL? - AWS: - NoSQL vs. SQL Databases - MongoDB 官方文档: - \ No newline at end of file + diff --git a/docs/database/redis/3-commonly-used-cache-read-and-write-strategies.md b/docs/database/redis/3-commonly-used-cache-read-and-write-strategies.md index 78d76a4f..6394a0c5 100644 --- a/docs/database/redis/3-commonly-used-cache-read-and-write-strategies.md +++ b/docs/database/redis/3-commonly-used-cache-read-and-write-strategies.md @@ -115,4 +115,4 @@ Write Behind Pattern 和 Read/Write Through Pattern 很相似,两者都是由 Write Behind Pattern 下 db 的写性能非常高,非常适合一些数据经常变化又对数据一致性要求没那么高的场景,比如浏览量、点赞量。 - \ No newline at end of file + diff --git a/docs/database/redis/cache-basics.md b/docs/database/redis/cache-basics.md index 259e8d6e..391e5bec 100644 --- a/docs/database/redis/cache-basics.md +++ b/docs/database/redis/cache-basics.md @@ -11,4 +11,4 @@ tag: - \ No newline at end of file + diff --git a/docs/database/redis/redis-cluster.md b/docs/database/redis/redis-cluster.md index 8e2b727a..60cd7dda 100644 --- a/docs/database/redis/redis-cluster.md +++ b/docs/database/redis/redis-cluster.md @@ -11,4 +11,4 @@ tag: - \ No newline at end of file + diff --git a/docs/database/redis/redis-common-blocking-problems-summary.md b/docs/database/redis/redis-common-blocking-problems-summary.md index ed7f7e95..8b129e0e 100644 --- a/docs/database/redis/redis-common-blocking-problems-summary.md +++ b/docs/database/redis/redis-common-blocking-problems-summary.md @@ -172,4 +172,4 @@ Redis 是典型的 CPU 密集型应用,不建议和其他多核 CPU 密集型 - Redis 阻塞的 6 大类场景分析与总结:https://mp.weixin.qq.com/s/eaZCEtTjTuEmXfUubVHjew - Redis 开发与运维笔记-Redis 的噩梦-阻塞:https://mp.weixin.qq.com/s/TDbpz9oLH6ifVv6ewqgSgA - \ No newline at end of file + diff --git a/docs/database/redis/redis-data-structures-01.md b/docs/database/redis/redis-data-structures-01.md index 00fde935..999e88b4 100644 --- a/docs/database/redis/redis-data-structures-01.md +++ b/docs/database/redis/redis-data-structures-01.md @@ -47,19 +47,19 @@ String 是一种二进制安全的数据类型,可以用来存储任何类型 ### 常用命令 -| 命令 | 介绍 | -| ------------------------------ | -------------------------------- | -| SET key value | 设置指定 key 的值 | -| SETNX key value | 只有在 key 不存在时设置 key 的值 | -| GET key | 获取指定 key 的值 | +| 命令 | 介绍 | +| ------------------------------- | -------------------------------- | +| SET key value | 设置指定 key 的值 | +| SETNX key value | 只有在 key 不存在时设置 key 的值 | +| GET key | 获取指定 key 的值 | | MSET key1 value1 key2 value2 …… | 设置一个或多个指定 key 的值 | -| MGET key1 key2 ... | 获取一个或多个指定 key 的值 | -| STRLEN key | 返回 key 所储存的字符串值的长度 | -| INCR key | 将 key 中储存的数字值增一 | -| DECR key | 将 key 中储存的数字值减一 | -| EXISTS key | 判断指定 key 是否存在 | -| DEL key(通用) | 删除指定的 key | -| EXPIRE key seconds(通用) | 给指定 key 设置过期时间 | +| MGET key1 key2 ... | 获取一个或多个指定 key 的值 | +| STRLEN key | 返回 key 所储存的字符串值的长度 | +| INCR key | 将 key 中储存的数字值增一 | +| DECR key | 将 key 中储存的数字值减一 | +| EXISTS key | 判断指定 key 是否存在 | +| DEL key(通用) | 删除指定的 key | +| EXPIRE key seconds(通用) | 给指定 key 设置过期时间 | 更多 Redis String 命令以及详细使用指南,请查看 Redis 官网对应的介绍: 。 @@ -485,13 +485,13 @@ value1 ## 总结 -| 数据类型 | 说明 | -| -------------------------------- | ------------------------------------------------- | -| String | 一种二进制安全的数据类型,可以用来存储任何类型的数据比如字符串、整数、浮点数、图片(图片的 base64 编码或者解码或者图片的路径)、序列化后的对象。 | -| List | Redis 的 List 的实现为一个双向链表,即可以支持反向查找和遍历,更方便操作,不过带来了部分额外的内存开销。 | -| Hash | 一个 String 类型的 field-value(键值对) 的映射表,特别适合用于存储对象,后续操作的时候,你可以直接修改这个对象中的某些字段的值。 | -| Set | 无序集合,集合中的元素没有先后顺序但都唯一,有点类似于 Java 中的 `HashSet` 。 | -| Zset | 和 Set 相比,Sorted Set 增加了一个权重参数 `score`,使得集合中的元素能够按 `score` 进行有序排列,还可以通过 `score` 的范围来获取元素的列表。有点像是 Java 中 `HashMap` 和 `TreeSet` 的结合体。 | +| 数据类型 | 说明 | +| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| String | 一种二进制安全的数据类型,可以用来存储任何类型的数据比如字符串、整数、浮点数、图片(图片的 base64 编码或者解码或者图片的路径)、序列化后的对象。 | +| List | Redis 的 List 的实现为一个双向链表,即可以支持反向查找和遍历,更方便操作,不过带来了部分额外的内存开销。 | +| Hash | 一个 String 类型的 field-value(键值对) 的映射表,特别适合用于存储对象,后续操作的时候,你可以直接修改这个对象中的某些字段的值。 | +| Set | 无序集合,集合中的元素没有先后顺序但都唯一,有点类似于 Java 中的 `HashSet` 。 | +| Zset | 和 Set 相比,Sorted Set 增加了一个权重参数 `score`,使得集合中的元素能够按 `score` 进行有序排列,还可以通过 `score` 的范围来获取元素的列表。有点像是 Java 中 `HashMap` 和 `TreeSet` 的结合体。 | ## 参考 @@ -500,4 +500,4 @@ value1 - Redis Data types tutorial: 。 - Redis 存储对象信息是用 Hash 还是 String : - \ No newline at end of file + diff --git a/docs/database/redis/redis-data-structures-02.md b/docs/database/redis/redis-data-structures-02.md index 474b6401..a083761f 100644 --- a/docs/database/redis/redis-data-structures-02.md +++ b/docs/database/redis/redis-data-structures-02.md @@ -211,11 +211,11 @@ user2 ## 总结 -| 数据类型 | 说明 | -| ---------------- | ------------------------------------------------------------ | +| 数据类型 | 说明 | +| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Bitmap | 你可以将 Bitmap 看作是一个存储二进制数字(0 和 1)的数组,数组中每个元素的下标叫做 offset(偏移量)。通过 Bitmap, 只需要一个 bit 位来表示某个元素对应的值或者状态,key 就是对应元素本身 。我们知道 8 个 bit 可以组成一个 byte,所以 Bitmap 本身会极大的节省储存空间。 | -| HyperLogLog | Redis 提供的 HyperLogLog 占用空间非常非常小,只需要 12k 的空间就能存储接近`2^64`个不同元素。不过,HyperLogLog 的计数结果并不是一个精确值,存在一定的误差(标准误差为 `0.81%` )。 | -| Geospatial index | Geospatial index(地理空间索引,简称 GEO) 主要用于存储地理位置信息,基于 Sorted Set 实现。 | +| HyperLogLog | Redis 提供的 HyperLogLog 占用空间非常非常小,只需要 12k 的空间就能存储接近`2^64`个不同元素。不过,HyperLogLog 的计数结果并不是一个精确值,存在一定的误差(标准误差为 `0.81%` )。 | +| Geospatial index | Geospatial index(地理空间索引,简称 GEO) 主要用于存储地理位置信息,基于 Sorted Set 实现。 | ## 参考 @@ -223,4 +223,4 @@ user2 - 《Redis 深度历险:核心原理与应用实践》1.6 四两拨千斤——HyperLogLog - 布隆过滤器,位图,HyperLogLog:https://hogwartsrico.github.io/2020/06/08/BloomFilter-HyperLogLog-BitMap/index.html - \ No newline at end of file + diff --git a/docs/database/redis/redis-memory-fragmentation.md b/docs/database/redis/redis-memory-fragmentation.md index f6f84379..1290b1e2 100644 --- a/docs/database/redis/redis-memory-fragmentation.md +++ b/docs/database/redis/redis-memory-fragmentation.md @@ -121,4 +121,4 @@ config set active-defrag-cycle-max 50 - Redis 核心技术与实战 - 极客时间 - 删除数据后,为什么内存占用率还是很高?:https://time.geekbang.org/column/article/289140 - Redis 源码解析——内存分配: - \ No newline at end of file + diff --git a/docs/database/redis/redis-persistence.md b/docs/database/redis/redis-persistence.md index e472822b..a7eaa524 100644 --- a/docs/database/redis/redis-persistence.md +++ b/docs/database/redis/redis-persistence.md @@ -196,4 +196,4 @@ AOF 校验机制是 Redis 在启动时对 AOF 文件进行检查,以判断文 - Redis AOF 持久化详解 - 程序员历小冰:http://remcarpediem.net/article/376c55d8/ - Redis RDB 与 AOF 持久化 · Analyze:https://wingsxdu.com/posts/database/redis/rdb-and-aof/ - \ No newline at end of file + diff --git a/docs/database/redis/redis-questions-01.md b/docs/database/redis/redis-questions-01.md index 8c471e25..87609252 100644 --- a/docs/database/redis/redis-questions-01.md +++ b/docs/database/redis/redis-questions-01.md @@ -259,13 +259,13 @@ struct __attribute__ ((__packed__)) sdshdr64 { 通过源码可以看出,SDS 共有五种实现方式 SDS_TYPE_5(并未用到)、SDS_TYPE_8、SDS_TYPE_16、SDS_TYPE_32、SDS_TYPE_64,其中只有后四种实际用到。Redis 会根据初始化的长度决定使用哪种类型,从而减少内存的使用。 -| 类型 | 字节 | 位 | -| -------- | ---- | ---- | -| sdshdr5 | < 1 | <8 | -| sdshdr8 | 1 | 8 | -| sdshdr16 | 2 | 16 | -| sdshdr32 | 4 | 32 | -| sdshdr64 | 8 | 64 | +| 类型 | 字节 | 位 | +| -------- | ---- | --- | +| sdshdr5 | < 1 | <8 | +| sdshdr8 | 1 | 8 | +| sdshdr16 | 2 | 16 | +| sdshdr32 | 4 | 32 | +| sdshdr64 | 8 | 64 | 对于后四种实现都包含了下面这 4 个属性: @@ -606,4 +606,4 @@ Redis 提供 6 种数据淘汰策略: - Redis 命令手册:https://www.redis.com.cn/commands.html - WHY Redis choose single thread (vs multi threads): [https://medium.com/@jychen7/sharing-redis-single-thread-vs-multi-threads-5870bd44d153](https://medium.com/@jychen7/sharing-redis-single-thread-vs-multi-threads-5870bd44d153) - \ No newline at end of file + diff --git a/docs/database/redis/redis-questions-02.md b/docs/database/redis/redis-questions-02.md index dd38e5fe..7b1efc34 100644 --- a/docs/database/redis/redis-questions-02.md +++ b/docs/database/redis/redis-questions-02.md @@ -496,7 +496,7 @@ Redis 中的大部分命令都是 O(1)时间复杂度,但也有少部分 O(n) ⚠️注意:由于慢查询日志会占用一定内存空间,如果设置最大记录条数过大,可能会导致内存占用过高的问题。 - `slowlog-log-slower-than`和`slowlog-max-len`的默认配置如下(可以自行修改): +`slowlog-log-slower-than`和`slowlog-max-len`的默认配置如下(可以自行修改): ```nginx # The following time is expressed in microseconds, so 1000000 is equivalent @@ -755,4 +755,4 @@ Cache Aside Pattern 中遇到写请求是这样的:更新 DB,然后直接删 - 一文详解 Redis 中 BigKey、HotKey 的发现与处理: - Redis 延迟问题全面排障指南:https://mp.weixin.qq.com/s/mIc6a9mfEGdaNDD3MmfFsg - \ No newline at end of file + diff --git a/docs/database/sql/sql-questions-01.md b/docs/database/sql/sql-questions-01.md index 70de96f8..22854616 100644 --- a/docs/database/sql/sql-questions-01.md +++ b/docs/database/sql/sql-questions-01.md @@ -189,17 +189,17 @@ ORDER BY vend_name DESC 下面的运算符可以在 `WHERE` 子句中使用: -| 运算符 | 描述 | -| :------ | :--------------------------------------------------------- | -| = | 等于 | +| 运算符 | 描述 | +| :------ | :----------------------------------------------------------- | +| = | 等于 | | <> | 不等于。 **注释:** 在 SQL 的一些版本中,该操作符可被写成 != | -| > | 大于 | -| < | 小于 | -| >= | 大于等于 | -| <= | 小于等于 | -| BETWEEN | 在某个范围内 | -| LIKE | 搜索某种模式 | -| IN | 指定针对某个列的多个可能值 | +| > | 大于 | +| < | 小于 | +| >= | 大于等于 | +| <= | 小于等于 | +| BETWEEN | 在某个范围内 | +| LIKE | 搜索某种模式 | +| IN | 指定针对某个列的多个可能值 | ### 返回固定价格的产品 @@ -1822,4 +1822,4 @@ WHERE cust_state = 'MI' or cust_state = 'IL' ORDER BY cust_name; ``` - \ No newline at end of file + diff --git a/docs/database/sql/sql-questions-02.md b/docs/database/sql/sql-questions-02.md index a3427d07..2a4a3e49 100644 --- a/docs/database/sql/sql-questions-02.md +++ b/docs/database/sql/sql-questions-02.md @@ -27,14 +27,14 @@ SQL 插入记录的方式汇总: 试卷作答记录表`exam_record`中,表已建好,其结构如下,请用一条语句将这两条记录插入表中。 -| Filed | Type | Null | Key | Extra | Default | Comment | -| ----------- | ---------- | ---- | ---- | -------------- | ------- | -------- | -| id | int(11) | NO | PRI | auto_increment | (NULL) | 自增 ID | -| uid | int(11) | NO | | | (NULL) | 用户 ID | -| exam_id | int(11) | NO | | | (NULL) | 试卷 ID | -| start_time | datetime | NO | | | (NULL) | 开始时间 | -| submit_time | datetime | YES | | | (NULL) | 提交时间 | -| score | tinyint(4) | YES | | | (NULL) | 得分 | +| Filed | Type | Null | Key | Extra | Default | Comment | +| ----------- | ---------- | ---- | --- | -------------- | ------- | -------- | +| id | int(11) | NO | PRI | auto_increment | (NULL) | 自增 ID | +| uid | int(11) | NO | | | (NULL) | 用户 ID | +| exam_id | int(11) | NO | | | (NULL) | 试卷 ID | +| start_time | datetime | NO | | | (NULL) | 开始时间 | +| submit_time | datetime | YES | | | (NULL) | 提交时间 | +| score | tinyint(4) | YES | | | (NULL) | 得分 | **答案**: @@ -51,14 +51,14 @@ INSERT INTO exam_record (uid, exam_id, start_time, submit_time, score) VALUES 表`exam_record`: -| Filed | Type | Null | Key | Extra | Default | Comment | -| ----------- | ---------- | ---- | ---- | -------------- | ------- | -------- | -| id | int(11) | NO | PRI | auto_increment | (NULL) | 自增 ID | -| uid | int(11) | NO | | | (NULL) | 用户 ID | -| exam_id | int(11) | NO | | | (NULL) | 试卷 ID | -| start_time | datetime | NO | | | (NULL) | 开始时间 | -| submit_time | datetime | YES | | | (NULL) | 提交时间 | -| score | tinyint(4) | YES | | | (NULL) | 得分 | +| Filed | Type | Null | Key | Extra | Default | Comment | +| ----------- | ---------- | ---- | --- | -------------- | ------- | -------- | +| id | int(11) | NO | PRI | auto_increment | (NULL) | 自增 ID | +| uid | int(11) | NO | | | (NULL) | 用户 ID | +| exam_id | int(11) | NO | | | (NULL) | 试卷 ID | +| start_time | datetime | NO | | | (NULL) | 开始时间 | +| submit_time | datetime | YES | | | (NULL) | 提交时间 | +| score | tinyint(4) | YES | | | (NULL) | 得分 | 我们已经创建了一张新表`exam_record_before_2021`用来备份 2021 年之前的试题作答记录,结构和`exam_record`表一致,请将 2021 年之前的已完成了的试题作答纪录导入到该表。 @@ -77,14 +77,14 @@ WHERE YEAR(submit_time) < 2021; 试题信息表`examination_info`: -| Filed | Type | Null | Key | Extra | Default | Comment | -| ------------ | ----------- | ---- | ---- | -------------- | ------- | ------------ | -| id | int(11) | NO | PRI | auto_increment | (NULL) | 自增 ID | -| exam_id | int(11) | NO | UNI | | (NULL) | 试卷 ID | -| tag | varchar(32) | YES | | | (NULL) | 类别标签 | -| difficulty | varchar(8) | YES | | | (NULL) | 难度 | -| duration | int(11) | NO | | | (NULL) | 时长(分钟数) | -| release_time | datetime | YES | | | (NULL) | 发布时间 | +| Filed | Type | Null | Key | Extra | Default | Comment | +| ------------ | ----------- | ---- | --- | -------------- | ------- | ------------ | +| id | int(11) | NO | PRI | auto_increment | (NULL) | 自增 ID | +| exam_id | int(11) | NO | UNI | | (NULL) | 试卷 ID | +| tag | varchar(32) | YES | | | (NULL) | 类别标签 | +| difficulty | varchar(8) | YES | | | (NULL) | 难度 | +| duration | int(11) | NO | | | (NULL) | 时长(分钟数) | +| release_time | datetime | YES | | | (NULL) | 发布时间 | **答案**: @@ -97,14 +97,14 @@ REPLACE INTO examination_info VALUES **描述**:现在有一张试卷信息表 `examination_info`, 表结构如下图所示: -| Filed | Type | Null | Key | Extra | Default | Comment | -| ------------ | -------- | ---- | ---- | -------------- | ------- | -------- | -| id | int(11) | NO | PRI | auto_increment | (NULL) | 自增 ID | -| exam_id | int(11) | NO | UNI | | (NULL) | 试卷 ID | -| tag | char(32) | YES | | | (NULL) | 类别标签 | -| difficulty | char(8) | YES | | | (NULL) | 难度 | -| duration | int(11) | NO | | | (NULL) | 时长 | -| release_time | datetime | YES | | | (NULL) | 发布时间 | +| Filed | Type | Null | Key | Extra | Default | Comment | +| ------------ | -------- | ---- | --- | -------------- | ------- | -------- | +| id | int(11) | NO | PRI | auto_increment | (NULL) | 自增 ID | +| exam_id | int(11) | NO | UNI | | (NULL) | 试卷 ID | +| tag | char(32) | YES | | | (NULL) | 类别标签 | +| difficulty | char(8) | YES | | | (NULL) | 难度 | +| duration | int(11) | NO | | | (NULL) | 时长 | +| release_time | datetime | YES | | | (NULL) | 发布时间 | 请把**examination_info**表中`tag`为`PYTHON`的`tag`字段全部修改为`Python`。 @@ -129,14 +129,14 @@ SET tag = REPLACE(tag,'PYTHON','Python') **描述**:现有一张试卷作答记录表 exam_record,其中包含多年来的用户作答试卷记录,结构如下表:作答记录表 `exam_record`: **`submit_time`** 为 完成时间 (注意这句话) -| Filed | Type | Null | Key | Extra | Default | Comment | -| ----------- | ---------- | ---- | ---- | -------------- | ------- | -------- | -| id | int(11) | NO | PRI | auto_increment | (NULL) | 自增 ID | -| uid | int(11) | NO | | | (NULL) | 用户 ID | -| exam_id | int(11) | NO | | | (NULL) | 试卷 ID | -| start_time | datetime | NO | | | (NULL) | 开始时间 | -| submit_time | datetime | YES | | | (NULL) | 提交时间 | -| score | tinyint(4) | YES | | | (NULL) | 得分 | +| Filed | Type | Null | Key | Extra | Default | Comment | +| ----------- | ---------- | ---- | --- | -------------- | ------- | -------- | +| id | int(11) | NO | PRI | auto_increment | (NULL) | 自增 ID | +| uid | int(11) | NO | | | (NULL) | 用户 ID | +| exam_id | int(11) | NO | | | (NULL) | 试卷 ID | +| start_time | datetime | NO | | | (NULL) | 开始时间 | +| submit_time | datetime | YES | | | (NULL) | 提交时间 | +| score | tinyint(4) | YES | | | (NULL) | 得分 | **题目要求**:请把 `exam_record` 表中 2021 年 9 月 1 日==之前==开始作答的==未完成==记录全部改为被动完成,即:将完成时间改为'2099-01-01 00:00:00',分数改为 0。 @@ -154,14 +154,14 @@ UPDATE exam_record SET submit_time = '2099-01-01 00:00:00', score = 0 WHERE DATE 作答记录表`exam_record:` **`start_time`** 是试卷开始时间`submit_time` 是交卷,即结束时间。 -| Filed | Type | Null | Key | Extra | Default | Comment | -| ----------- | ---------- | ---- | ---- | -------------- | ------- | -------- | -| id | int(11) | NO | PRI | auto_increment | (NULL) | 自增 ID | -| uid | int(11) | NO | | | (NULL) | 用户 ID | -| exam_id | int(11) | NO | | | (NULL) | 试卷 ID | -| start_time | datetime | NO | | | (NULL) | 开始时间 | -| submit_time | datetime | YES | | | (NULL) | 提交时间 | -| score | tinyint(4) | YES | | | (NULL) | 得分 | +| Filed | Type | Null | Key | Extra | Default | Comment | +| ----------- | ---------- | ---- | --- | -------------- | ------- | -------- | +| id | int(11) | NO | PRI | auto_increment | (NULL) | 自增 ID | +| uid | int(11) | NO | | | (NULL) | 用户 ID | +| exam_id | int(11) | NO | | | (NULL) | 试卷 ID | +| start_time | datetime | NO | | | (NULL) | 开始时间 | +| submit_time | datetime | YES | | | (NULL) | 提交时间 | +| score | tinyint(4) | YES | | | (NULL) | 得分 | **要求**:请删除`exam_record`表中作答时间小于 5 分钟整且分数不及格(及格线为 60 分)的记录; @@ -194,7 +194,7 @@ YEAR:年 # TIMESTAMPDIFF函数返回datetime_expr2 - datetime_expr1的结果(人话: 后面的 - 前面的 即2-1),其中datetime_expr1和datetime_expr2可以是DATE或DATETIME类型值(人话:可以是“2023-01-01”, 也可以是“2023-01-01- 00:00:00”) ``` - 这题需要进行分钟的比较,那么就是 TIMESTAMPDIFF(MINUTE, 开始时间, 结束时间) < 5 +这题需要进行分钟的比较,那么就是 TIMESTAMPDIFF(MINUTE, 开始时间, 结束时间) < 5 **答案**: @@ -212,14 +212,14 @@ DELETE FROM exam_record WHERE TIMESTAMPDIFF(MINUTE, start_time, submit_time) < 5 作答记录表`exam_record`:`start_time` 是试卷开始时间,`submit_time` 是交卷时间,即结束时间,如果未完成的话,则为空。 -| Filed | Type | Null | Key | Extra | Default | Comment | -| ----------- | ---------- | :--: | ---- | -------------- | ------- | -------- | -| id | int(11) | NO | PRI | auto_increment | (NULL) | 自增 ID | -| uid | int(11) | NO | | | (NULL) | 用户 ID | -| exam_id | int(11) | NO | | | (NULL) | 试卷 ID | -| start_time | datetime | NO | | | (NULL) | 开始时间 | -| submit_time | datetime | YES | | | (NULL) | 提交时间 | -| score | tinyint(4) | YES | | | (NULL) | 分数 | +| Filed | Type | Null | Key | Extra | Default | Comment | +| ----------- | ---------- | :--: | --- | -------------- | ------- | -------- | +| id | int(11) | NO | PRI | auto_increment | (NULL) | 自增 ID | +| uid | int(11) | NO | | | (NULL) | 用户 ID | +| exam_id | int(11) | NO | | | (NULL) | 试卷 ID | +| start_time | datetime | NO | | | (NULL) | 开始时间 | +| submit_time | datetime | YES | | | (NULL) | 提交时间 | +| score | tinyint(4) | YES | | | (NULL) | 分数 | **要求**:请删除`exam_record`表中未完成作答==或==作答时间小于 5 分钟整的记录中,开始作答时间最早的 3 条记录。 @@ -240,14 +240,14 @@ LIMIT 3 **描述**:现有一张试卷作答记录表 exam_record,其中包含多年来的用户作答试卷记录,结构如下表: -| Filed | Type | Null | Key | Extra | Default | Comment | -| ----------- | ---------- | :--: | ---- | -------------- | ------- | -------- | -| id | int(11) | NO | PRI | auto_increment | (NULL) | 自增 ID | -| uid | int(11) | NO | | | (NULL) | 用户 ID | -| exam_id | int(11) | NO | | | (NULL) | 试卷 ID | -| start_time | datetime | NO | | | (NULL) | 开始时间 | -| submit_time | datetime | YES | | | (NULL) | 提交时间 | -| score | tinyint(4) | YES | | | (NULL) | 分数 | +| Filed | Type | Null | Key | Extra | Default | Comment | +| ----------- | ---------- | :--: | --- | -------------- | ------- | -------- | +| id | int(11) | NO | PRI | auto_increment | (NULL) | 自增 ID | +| uid | int(11) | NO | | | (NULL) | 用户 ID | +| exam_id | int(11) | NO | | | (NULL) | 试卷 ID | +| start_time | datetime | NO | | | (NULL) | 开始时间 | +| submit_time | datetime | YES | | | (NULL) | 提交时间 | +| score | tinyint(4) | YES | | | (NULL) | 分数 | **要求**:请删除`exam_record`表中所有记录,==并重置自增主键== @@ -277,29 +277,29 @@ TRUNCATE exam_record; 原来的用户信息表: -| Filed | Type | Null | Key | Default | Extra | Comment | -| ------------- | ----------- | ---- | ---- | ----------------- | -------------- | -------- | -| id | int(11) | NO | PRI | (NULL) | auto_increment | 自增 ID | -| uid | int(11) | NO | UNI | (NULL) | | 用户 ID | -| nick_name | varchar(64) | YES | | (NULL) | | 昵称 | -| achievement | int(11) | YES | | 0 | | 成就值 | -| level | int(11) | YES | | (NULL) | | 用户等级 | -| job | varchar(32) | YES | | (NULL) | | 职业方向 | -| register_time | datetime | YES | | CURRENT_TIMESTAMP | | 注册时间 | +| Filed | Type | Null | Key | Default | Extra | Comment | +| ------------- | ----------- | ---- | --- | ----------------- | -------------- | -------- | +| id | int(11) | NO | PRI | (NULL) | auto_increment | 自增 ID | +| uid | int(11) | NO | UNI | (NULL) | | 用户 ID | +| nick_name | varchar(64) | YES | | (NULL) | | 昵称 | +| achievement | int(11) | YES | | 0 | | 成就值 | +| level | int(11) | YES | | (NULL) | | 用户等级 | +| job | varchar(32) | YES | | (NULL) | | 职业方向 | +| register_time | datetime | YES | | CURRENT_TIMESTAMP | | 注册时间 | 作为数据分析师,请**创建一张优质用户信息表 user_info_vip**,表结构和用户信息表一致。 你应该返回的输出如下表格所示,请写出建表语句将表格中所有限制和说明记录到表里。 -| Filed | Type | Null | Key | Default | Extra | Comment | -| ------------- | ----------- | ---- | ---- | ----------------- | -------------- | -------- | -| id | int(11) | NO | PRI | (NULL) | auto_increment | 自增 ID | -| uid | int(11) | NO | UNI | (NULL) | | 用户 ID | -| nick_name | varchar(64) | YES | | (NULL) | | 昵称 | -| achievement | int(11) | YES | | 0 | | 成就值 | -| level | int(11) | YES | | (NULL) | | 用户等级 | -| job | varchar(32) | YES | | (NULL) | | 职业方向 | -| register_time | datetime | YES | | CURRENT_TIMESTAMP | | 注册时间 | +| Filed | Type | Null | Key | Default | Extra | Comment | +| ------------- | ----------- | ---- | --- | ----------------- | -------------- | -------- | +| id | int(11) | NO | PRI | (NULL) | auto_increment | 自增 ID | +| uid | int(11) | NO | UNI | (NULL) | | 用户 ID | +| nick_name | varchar(64) | YES | | (NULL) | | 昵称 | +| achievement | int(11) | YES | | 0 | | 成就值 | +| level | int(11) | YES | | (NULL) | | 用户等级 | +| job | varchar(32) | YES | | (NULL) | | 职业方向 | +| register_time | datetime | YES | | CURRENT_TIMESTAMP | | 注册时间 | **思路**:如果这题给出了旧表的名称,可直接`create table 新表 as select * from 旧表;` 但是这题并没有给出旧表名称,所以需要自己创建,注意默认值和键的创建即可,比较简单。(注意:如果是在牛客网上面执行,请注意 comment 中要和题目中的 comment 保持一致,包括大小写,否则不通过,还有字符也要设置) @@ -323,15 +323,15 @@ CREATE TABLE IF NOT EXISTS user_info_vip( **用户信息表 `user_info`:** -| Filed | Type | Null | Key | Default | Extra | Comment | -| ------------- | ----------- | ---- | ---- | ----------------- | -------------- | -------- | -| id | int(11) | NO | PRI | (NULL) | auto_increment | 自增 ID | -| uid | int(11) | NO | UNI | (NULL) | | 用户 ID | -| nick_name | varchar(64) | YES | | (NULL) | | 昵称 | -| achievement | int(11) | YES | | 0 | | 成就值 | -| level | int(11) | YES | | (NULL) | | 用户等级 | -| job | varchar(32) | YES | | (NULL) | | 职业方向 | -| register_time | datetime | YES | | CURRENT_TIMESTAMP | | 注册时间 | +| Filed | Type | Null | Key | Default | Extra | Comment | +| ------------- | ----------- | ---- | --- | ----------------- | -------------- | -------- | +| id | int(11) | NO | PRI | (NULL) | auto_increment | 自增 ID | +| uid | int(11) | NO | UNI | (NULL) | | 用户 ID | +| nick_name | varchar(64) | YES | | (NULL) | | 昵称 | +| achievement | int(11) | YES | | 0 | | 成就值 | +| level | int(11) | YES | | (NULL) | | 用户等级 | +| job | varchar(32) | YES | | (NULL) | | 职业方向 | +| register_time | datetime | YES | | CURRENT_TIMESTAMP | | 注册时间 | **要求:**请在用户信息表,字段 `level` 的后面增加一列最多可保存 15 个汉字的字段 `school`;并将表中 `job` 列名改为 `profession`,同时 `varchar` 字段长度变为 10;`achievement` 的默认值设置为 0。 @@ -382,11 +382,11 @@ DROP TABLE IF EXISTS exam_record_2014; 根据题意,将返回如下结果: -| examination_info | 0 | PRIMARY | 1 | id | A | 0 | | | | BTREE | -| ---------------- | ---- | ---------------- | ---- | -------- | ---- | ---- | ---- | ---- | ---- | -------- | -| examination_info | 0 | uniq_idx_exam_id | 1 | exam_id | A | 0 | | | YES | BTREE | -| examination_info | 1 | idx_duration | 1 | duration | A | 0 | | | | BTREE | -| examination_info | 1 | full_idx_tag | 1 | tag | | 0 | | | YES | FULLTEXT | +| examination_info | 0 | PRIMARY | 1 | id | A | 0 | | | | BTREE | +| ---------------- | --- | ---------------- | --- | -------- | --- | --- | --- | --- | --- | -------- | +| examination_info | 0 | uniq_idx_exam_id | 1 | exam_id | A | 0 | | | YES | BTREE | +| examination_info | 1 | idx_duration | 1 | duration | A | 0 | | | | BTREE | +| examination_info | 1 | full_idx_tag | 1 | tag | | 0 | | | YES | FULLTEXT | 备注:后台会通过 `SHOW INDEX FROM examination_info` 语句来对比输出结果 @@ -447,4 +447,4 @@ DROP INDEX uniq_idx_exam_id ON examination_info; DROP INDEX full_idx_tag ON examination_info; ``` - \ No newline at end of file + diff --git a/docs/database/sql/sql-questions-03.md b/docs/database/sql/sql-questions-03.md index 9f8807db..78590e2a 100644 --- a/docs/database/sql/sql-questions-03.md +++ b/docs/database/sql/sql-questions-03.md @@ -20,31 +20,31 @@ tag: 示例数据:`examination_info`(`exam_id` 试卷 ID, tag 试卷类别, `difficulty` 试卷难度, `duration` 考试时长, `release_time` 发布时间) -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | ---- | ---------- | -------- | ------------------- | -| 1 | 9001 | SQL | hard | 60 | 2020-01-01 10:00:00 | -| 2 | 9002 | 算法 | medium | 80 | 2020-08-02 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | ---- | ---------- | -------- | ------------------- | +| 1 | 9001 | SQL | hard | 60 | 2020-01-01 10:00:00 | +| 2 | 9002 | 算法 | medium | 80 | 2020-08-02 10:00:00 | 示例数据:`exam_record`(uid 用户 ID, exam_id 试卷 ID, start_time 开始作答时间, submit_time 交卷时间, score 得分) -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:01 | 80 | -| 2 | 1001 | 9001 | 2021-05-02 10:01:01 | 2021-05-02 10:30:01 | 81 | -| 3 | 1001 | 9001 | 2021-06-02 19:01:01 | 2021-06-02 19:31:01 | 84 | -| 4 | 1001 | 9002 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 89 | -| 5 | 1001 | 9001 | 2021-09-02 12:01:01 | (NULL) | (NULL) | -| 6 | 1001 | 9002 | 2021-09-01 12:01:01 | (NULL) | (NULL) | -| 7 | 1002 | 9002 | 2021-02-02 19:01:01 | 2021-02-02 19:30:01 | 87 | -| 8 | 1002 | 9001 | 2021-05-05 18:01:01 | 2021-05-05 18:59:02 | 90 | -| 9 | 1003 | 9001 | 2021-09-07 12:01:01 | 2021-09-07 10:31:01 | 50 | -| 10 | 1004 | 9001 | 2021-09-06 10:01:01 | (NULL) | (NULL) | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:01 | 80 | +| 2 | 1001 | 9001 | 2021-05-02 10:01:01 | 2021-05-02 10:30:01 | 81 | +| 3 | 1001 | 9001 | 2021-06-02 19:01:01 | 2021-06-02 19:31:01 | 84 | +| 4 | 1001 | 9002 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 89 | +| 5 | 1001 | 9001 | 2021-09-02 12:01:01 | (NULL) | (NULL) | +| 6 | 1001 | 9002 | 2021-09-01 12:01:01 | (NULL) | (NULL) | +| 7 | 1002 | 9002 | 2021-02-02 19:01:01 | 2021-02-02 19:30:01 | 87 | +| 8 | 1002 | 9001 | 2021-05-05 18:01:01 | 2021-05-05 18:59:02 | 90 | +| 9 | 1003 | 9001 | 2021-09-07 12:01:01 | 2021-09-07 10:31:01 | 50 | +| 10 | 1004 | 9001 | 2021-09-06 10:01:01 | (NULL) | (NULL) | 根据输入你的查询结果如下: -| tag | difficulty | clip_avg_score | -| ---- | ---------- | -------------- | -| SQL | hard | 81.7 | +| tag | difficulty | clip_avg_score | +| --- | ---------- | -------------- | +| SQL | hard | 81.7 | 从`examination_info`表可知,试卷 9001 为高难度 SQL 试卷,该试卷被作答的得分有[80,81,84,90,50],去除最高分和最低分后为[80,81,84],平均分为 81.6666667,保留一位小数后为 81.7 @@ -199,18 +199,18 @@ WHERE info.exam_id = record.exam_id 示例数据 `exam_record` 表(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:01 | 80 | -| 2 | 1001 | 9001 | 2021-05-02 10:01:01 | 2021-05-02 10:30:01 | 81 | -| 3 | 1001 | 9001 | 2021-06-02 19:01:01 | 2021-06-02 19:31:01 | 84 | -| 4 | 1001 | 9002 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 89 | -| 5 | 1001 | 9001 | 2021-09-02 12:01:01 | (NULL) | (NULL) | -| 6 | 1001 | 9002 | 2021-09-01 12:01:01 | (NULL) | (NULL) | -| 7 | 1002 | 9002 | 2021-02-02 19:01:01 | 2021-02-02 19:30:01 | 87 | -| 8 | 1002 | 9001 | 2021-05-05 18:01:01 | 2021-05-05 18:59:02 | 90 | -| 9 | 1003 | 9001 | 2021-09-07 12:01:01 | 2021-09-07 10:31:01 | 50 | -| 10 | 1004 | 9001 | 2021-09-06 10:01:01 | (NULL) | (NULL) | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:01 | 80 | +| 2 | 1001 | 9001 | 2021-05-02 10:01:01 | 2021-05-02 10:30:01 | 81 | +| 3 | 1001 | 9001 | 2021-06-02 19:01:01 | 2021-06-02 19:31:01 | 84 | +| 4 | 1001 | 9002 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 89 | +| 5 | 1001 | 9001 | 2021-09-02 12:01:01 | (NULL) | (NULL) | +| 6 | 1001 | 9002 | 2021-09-01 12:01:01 | (NULL) | (NULL) | +| 7 | 1002 | 9002 | 2021-02-02 19:01:01 | 2021-02-02 19:30:01 | 87 | +| 8 | 1002 | 9001 | 2021-05-05 18:01:01 | 2021-05-05 18:59:02 | 90 | +| 9 | 1003 | 9001 | 2021-09-07 12:01:01 | 2021-09-07 10:31:01 | 50 | +| 10 | 1004 | 9001 | 2021-09-06 10:01:01 | (NULL) | (NULL) | 示例输出: @@ -220,7 +220,7 @@ WHERE info.exam_id = record.exam_id 解释:表示截止当前,有 11 次试卷作答记录,已完成的作答次数为 7 次(中途退出的为未完成状态,其交卷时间和份数为 NULL),已完成的试卷有 9001 和 9002 两份。 -**思路**: 这题一看到统计次数,肯定第一时间就要想到用`COUNT`这个函数来解决,问题是要统计不同的记录,该怎么来写?使用子查询就能解决这个题目(这题用 case when 也能写出来,解法类似,逻辑不同而已);首先在做这个题之前,让我们先来了解一下`COUNT`的基本用法; +**思路**: 这题一看到统计次数,肯定第一时间就要想到用`COUNT`这个函数来解决,问题是要统计不同的记录,该怎么来写?使用子查询就能解决这个题目(这题用 case when 也能写出来,解法类似,逻辑不同而已);首先在做这个题之前,让我们先来了解一下`COUNT`的基本用法; `COUNT()` 函数的基本语法如下所示: @@ -287,25 +287,25 @@ FROM 示例数据 exam_record 表(uid 用户 ID, exam_id 试卷 ID, start_time 开始作答时间, submit_time 交卷时间, score 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:01 | 80 | -| 2 | 1002 | 9001 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 89 | -| 3 | 1002 | 9002 | 2021-09-02 12:01:01 | (NULL) | (NULL) | -| 4 | 1002 | 9003 | 2021-09-01 12:01:01 | (NULL) | (NULL) | -| 5 | 1002 | 9001 | 2021-02-02 19:01:01 | 2021-02-02 19:30:01 | 87 | -| 6 | 1002 | 9002 | 2021-05-05 18:01:01 | 2021-05-05 18:59:02 | 90 | -| 7 | 1003 | 9002 | 2021-02-06 12:01:01 | (NULL) | (NULL) | -| 8 | 1003 | 9003 | 2021-09-07 10:01:01 | 2021-09-07 10:31:01 | 86 | -| 9 | 1004 | 9003 | 2021-09-06 12:01:01 | (NULL) | (NULL) | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:01 | 80 | +| 2 | 1002 | 9001 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 89 | +| 3 | 1002 | 9002 | 2021-09-02 12:01:01 | (NULL) | (NULL) | +| 4 | 1002 | 9003 | 2021-09-01 12:01:01 | (NULL) | (NULL) | +| 5 | 1002 | 9001 | 2021-02-02 19:01:01 | 2021-02-02 19:30:01 | 87 | +| 6 | 1002 | 9002 | 2021-05-05 18:01:01 | 2021-05-05 18:59:02 | 90 | +| 7 | 1003 | 9002 | 2021-02-06 12:01:01 | (NULL) | (NULL) | +| 8 | 1003 | 9003 | 2021-09-07 10:01:01 | 2021-09-07 10:31:01 | 86 | +| 9 | 1004 | 9003 | 2021-09-06 12:01:01 | (NULL) | (NULL) | `examination_info` 表(`exam_id` 试卷 ID, `tag` 试卷类别, `difficulty` 试卷难度, `duration` 考试时长, `release_time` 发布时间) -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | ---- | ---------- | -------- | ------------------- | -| 1 | 9001 | SQL | hard | 60 | 2020-01-01 10:00:00 | -| 2 | 9002 | SQL | easy | 60 | 2020-02-01 10:00:00 | -| 3 | 9003 | 算法 | medium | 80 | 2020-08-02 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | ---- | ---------- | -------- | ------------------- | +| 1 | 9001 | SQL | hard | 60 | 2020-01-01 10:00:00 | +| 2 | 9002 | SQL | easy | 60 | 2020-02-01 10:00:00 | +| 3 | 9003 | 算法 | medium | 80 | 2020-08-02 10:00:00 | 示例输出数据: @@ -363,28 +363,28 @@ WHERE info.exam_id = record.exam_id `exam_record` 表(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分) -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2021-07-02 09:01:01 | 2021-07-02 09:21:01 | 80 | -| 2 | 1002 | 9001 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 81 | -| 3 | 1002 | 9002 | 2021-09-02 12:01:01 | (NULL) | (NULL) | -| 4 | 1002 | 9003 | 2021-09-01 12:01:01 | (NULL) | (NULL) | -| 5 | 1002 | 9001 | 2021-07-02 19:01:01 | 2021-07-02 19:30:01 | 82 | -| 6 | 1002 | 9002 | 2021-07-05 18:01:01 | 2021-07-05 18:59:02 | 90 | -| 7 | 1003 | 9002 | 2021-07-06 12:01:01 | (NULL) | (NULL) | -| 8 | 1003 | 9003 | 2021-09-07 10:01:01 | 2021-09-07 10:31:01 | 86 | -| 9 | 1004 | 9003 | 2021-09-06 12:01:01 | (NULL) | (NULL) | -| 10 | 1002 | 9003 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 81 | -| 11 | 1005 | 9001 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 88 | -| 12 | 1006 | 9002 | 2021-09-02 12:11:01 | 2021-09-02 12:31:01 | 89 | -| 13 | 1007 | 9002 | 2020-09-02 12:11:01 | 2020-09-02 12:31:01 | 89 | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2021-07-02 09:01:01 | 2021-07-02 09:21:01 | 80 | +| 2 | 1002 | 9001 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 81 | +| 3 | 1002 | 9002 | 2021-09-02 12:01:01 | (NULL) | (NULL) | +| 4 | 1002 | 9003 | 2021-09-01 12:01:01 | (NULL) | (NULL) | +| 5 | 1002 | 9001 | 2021-07-02 19:01:01 | 2021-07-02 19:30:01 | 82 | +| 6 | 1002 | 9002 | 2021-07-05 18:01:01 | 2021-07-05 18:59:02 | 90 | +| 7 | 1003 | 9002 | 2021-07-06 12:01:01 | (NULL) | (NULL) | +| 8 | 1003 | 9003 | 2021-09-07 10:01:01 | 2021-09-07 10:31:01 | 86 | +| 9 | 1004 | 9003 | 2021-09-06 12:01:01 | (NULL) | (NULL) | +| 10 | 1002 | 9003 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 81 | +| 11 | 1005 | 9001 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 88 | +| 12 | 1006 | 9002 | 2021-09-02 12:11:01 | 2021-09-02 12:31:01 | 89 | +| 13 | 1007 | 9002 | 2020-09-02 12:11:01 | 2020-09-02 12:31:01 | 89 | 请计算 2021 年每个月里试卷作答区用户平均月活跃天数 `avg_active_days` 和月度活跃人数 `mau`,上面数据的示例输出如下: -| month | avg_active_days | mau | -| ------ | --------------- | ---- | -| 202107 | 1.50 | 2 | -| 202109 | 1.25 | 4 | +| month | avg_active_days | mau | +| ------ | --------------- | --- | +| 202107 | 1.50 | 2 | +| 202109 | 1.25 | 4 | **解释**:2021 年 7 月有 2 人活跃,共活跃了 3 天(1001 活跃 1 天,1002 活跃 2 天),平均活跃天数 1.5;2021 年 9 月有 4 人活跃,共活跃了 5 天,平均活跃天数 1.25,结果保留 2 位小数。 @@ -416,13 +416,13 @@ GROUP BY MONTH **描述**:现有一张题目练习记录表 `practice_record`,示例内容如下: -| id | uid | question_id | submit_time | score | -| ---- | ---- | ----------- | ------------------- | ----- | -| 1 | 1001 | 8001 | 2021-08-02 11:41:01 | 60 | -| 2 | 1002 | 8001 | 2021-09-02 19:30:01 | 50 | -| 3 | 1002 | 8001 | 2021-09-02 19:20:01 | 70 | -| 4 | 1002 | 8002 | 2021-09-02 19:38:01 | 70 | -| 5 | 1003 | 8002 | 2021-08-01 19:38:01 | 80 | +| id | uid | question_id | submit_time | score | +| --- | ---- | ----------- | ------------------- | ----- | +| 1 | 1001 | 8001 | 2021-08-02 11:41:01 | 60 | +| 2 | 1002 | 8001 | 2021-09-02 19:30:01 | 50 | +| 3 | 1002 | 8001 | 2021-09-02 19:20:01 | 70 | +| 4 | 1002 | 8002 | 2021-09-02 19:38:01 | 70 | +| 5 | 1003 | 8002 | 2021-08-01 19:38:01 | 80 | 请从中统计出 2021 年每个月里用户的月总刷题数 `month_q_cnt` 和日均刷题数 `avg_day_q_cnt`(按月份升序排序)以及该年的总体情况,示例数据输出如下: @@ -495,34 +495,34 @@ ORDER BY submit_month **描述**:现有试卷作答记录表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分),示例数据如下: -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2021-07-02 09:01:01 | 2021-07-02 09:21:01 | 80 | -| 2 | 1002 | 9001 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 81 | -| 3 | 1002 | 9002 | 2021-09-02 12:01:01 | (NULL) | (NULL) | -| 4 | 1002 | 9003 | 2021-09-01 12:01:01 | (NULL) | (NULL) | -| 5 | 1002 | 9001 | 2021-07-02 19:01:01 | 2021-07-02 19:30:01 | 82 | -| 6 | 1002 | 9002 | 2021-07-05 18:01:01 | 2021-07-05 18:59:02 | 90 | -| 7 | 1003 | 9002 | 2021-07-06 12:01:01 | (NULL) | (NULL) | -| 8 | 1003 | 9003 | 2021-09-07 10:01:01 | 2021-09-07 10:31:01 | 86 | -| 9 | 1004 | 9003 | 2021-09-06 12:01:01 | (NULL) | (NULL) | -| 10 | 1002 | 9003 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 81 | -| 11 | 1005 | 9001 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 88 | -| 12 | 1006 | 9002 | 2021-09-02 12:11:01 | 2021-09-02 12:31:01 | 89 | -| 13 | 1007 | 9002 | 2020-09-02 12:11:01 | 2020-09-02 12:31:01 | 89 | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2021-07-02 09:01:01 | 2021-07-02 09:21:01 | 80 | +| 2 | 1002 | 9001 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 81 | +| 3 | 1002 | 9002 | 2021-09-02 12:01:01 | (NULL) | (NULL) | +| 4 | 1002 | 9003 | 2021-09-01 12:01:01 | (NULL) | (NULL) | +| 5 | 1002 | 9001 | 2021-07-02 19:01:01 | 2021-07-02 19:30:01 | 82 | +| 6 | 1002 | 9002 | 2021-07-05 18:01:01 | 2021-07-05 18:59:02 | 90 | +| 7 | 1003 | 9002 | 2021-07-06 12:01:01 | (NULL) | (NULL) | +| 8 | 1003 | 9003 | 2021-09-07 10:01:01 | 2021-09-07 10:31:01 | 86 | +| 9 | 1004 | 9003 | 2021-09-06 12:01:01 | (NULL) | (NULL) | +| 10 | 1002 | 9003 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 81 | +| 11 | 1005 | 9001 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 88 | +| 12 | 1006 | 9002 | 2021-09-02 12:11:01 | 2021-09-02 12:31:01 | 89 | +| 13 | 1007 | 9002 | 2020-09-02 12:11:01 | 2020-09-02 12:31:01 | 89 | 还有一张试卷信息表 `examination_info`(`exam_id` 试卷 ID, `tag` 试卷类别, `difficulty` 试卷难度, `duration` 考试时长, `release_time` 发布时间),示例数据如下: -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | ---- | ---------- | -------- | ------------------- | -| 1 | 9001 | SQL | hard | 60 | 2020-01-01 10:00:00 | -| 2 | 9002 | SQL | easy | 60 | 2020-02-01 10:00:00 | -| 3 | 9003 | 算法 | medium | 80 | 2020-08-02 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | ---- | ---------- | -------- | ------------------- | +| 1 | 9001 | SQL | hard | 60 | 2020-01-01 10:00:00 | +| 2 | 9002 | SQL | easy | 60 | 2020-02-01 10:00:00 | +| 3 | 9003 | 算法 | medium | 80 | 2020-08-02 10:00:00 | 请统计 2021 年每个未完成试卷作答数大于 1 的有效用户的数据(有效用户指完成试卷作答数至少为 1 且未完成数小于 5),输出用户 ID、未完成试卷作答数、完成试卷作答数、作答过的试卷 tag 集合,按未完成试卷数量由多到少排序。示例数据的输出结果如下: -| uid | incomplete_cnt | complete_cnt | detail | -| ---- | -------------- | ------------ | ------------------------------------------------------------ | +| uid | incomplete_cnt | complete_cnt | detail | +| ---- | -------------- | ------------ | --------------------------------------------------------------------------- | | 1002 | 2 | 4 | 2021-09-01:算法;2021-07-02:SQL;2021-09-02:SQL;2021-09-05:SQL;2021-07-05:SQL | **解释**:2021 年的作答记录中,除了 1004,其他用户均满足有效用户定义,但只有 1002 未完成试卷数大于 1,因此只输出 1002,detail 中是 1002 作答过的试卷{日期:tag}集合,日期和 tag 间用 **:** 连接,多元素间用 **;** 连接。 @@ -591,29 +591,29 @@ ORDER BY incomplete_cnt DESC **描述**:现有试卷作答记录表 `exam_record`(`uid`:用户 ID, `exam_id`:试卷 ID, `start_time`:开始作答时间, `submit_time`:交卷时间,没提交的话为 NULL, `score`:得分),示例数据如下: -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2021-07-02 09:01:01 | (NULL) | (NULL) | -| 2 | 1002 | 9003 | 2021-09-01 12:01:01 | 2021-09-01 12:21:01 | 60 | -| 3 | 1002 | 9002 | 2021-09-02 12:01:01 | 2021-09-02 12:31:01 | 70 | -| 4 | 1002 | 9001 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 81 | -| 5 | 1002 | 9002 | 2021-07-06 12:01:01 | (NULL) | (NULL) | -| 6 | 1003 | 9003 | 2021-09-07 10:01:01 | 2021-09-07 10:31:01 | 86 | -| 7 | 1003 | 9003 | 2021-09-08 12:01:01 | 2021-09-08 12:11:01 | 40 | -| 8 | 1003 | 9001 | 2021-09-08 13:01:01 | (NULL) | (NULL) | -| 9 | 1003 | 9002 | 2021-09-08 14:01:01 | (NULL) | (NULL) | -| 10 | 1003 | 9003 | 2021-09-08 15:01:01 | (NULL) | (NULL) | -| 11 | 1005 | 9001 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 88 | -| 12 | 1005 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 88 | -| 13 | 1005 | 9002 | 2021-09-02 12:11:01 | 2021-09-02 12:31:01 | 89 | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2021-07-02 09:01:01 | (NULL) | (NULL) | +| 2 | 1002 | 9003 | 2021-09-01 12:01:01 | 2021-09-01 12:21:01 | 60 | +| 3 | 1002 | 9002 | 2021-09-02 12:01:01 | 2021-09-02 12:31:01 | 70 | +| 4 | 1002 | 9001 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 81 | +| 5 | 1002 | 9002 | 2021-07-06 12:01:01 | (NULL) | (NULL) | +| 6 | 1003 | 9003 | 2021-09-07 10:01:01 | 2021-09-07 10:31:01 | 86 | +| 7 | 1003 | 9003 | 2021-09-08 12:01:01 | 2021-09-08 12:11:01 | 40 | +| 8 | 1003 | 9001 | 2021-09-08 13:01:01 | (NULL) | (NULL) | +| 9 | 1003 | 9002 | 2021-09-08 14:01:01 | (NULL) | (NULL) | +| 10 | 1003 | 9003 | 2021-09-08 15:01:01 | (NULL) | (NULL) | +| 11 | 1005 | 9001 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 88 | +| 12 | 1005 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 88 | +| 13 | 1005 | 9002 | 2021-09-02 12:11:01 | 2021-09-02 12:31:01 | 89 | 试卷信息表 `examination_info`(`exam_id`:试卷 ID, `tag`:试卷类别, `difficulty`:试卷难度, `duration`:考试时长, `release_time`:发布时间),示例数据如下: -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | ---- | ---------- | -------- | ------------------- | -| 1 | 9001 | SQL | hard | 60 | 2020-01-01 10:00:00 | -| 2 | 9002 | C++ | easy | 60 | 2020-02-01 10:00:00 | -| 3 | 9003 | 算法 | medium | 80 | 2020-08-02 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | ---- | ---------- | -------- | ------------------- | +| 1 | 9001 | SQL | hard | 60 | 2020-01-01 10:00:00 | +| 2 | 9002 | C++ | easy | 60 | 2020-02-01 10:00:00 | +| 3 | 9003 | 算法 | medium | 80 | 2020-08-02 10:00:00 | 请从表中统计出 “当月均完成试卷数”不小于 3 的用户们爱作答的类别及作答次数,按次数降序输出,示例输出如下: @@ -658,51 +658,51 @@ ORDER BY tag_cnt DESC **描述**:现有用户信息表 `user_info`(`uid` 用户 ID,`nick_name` 昵称, `achievement` 成就值, `level` 等级, `job` 职业方向, `register_time` 注册时间),示例数据如下: -| id | uid | nick_name | achievement | level | job | register_time | -| ---- | ---- | --------- | ----------- | ----- | ---- | ------------------- | -| 1 | 1001 | 牛客 1 号 | 3100 | 7 | 算法 | 2020-01-01 10:00:00 | -| 2 | 1002 | 牛客 2 号 | 2100 | 6 | 算法 | 2020-01-01 10:00:00 | -| 3 | 1003 | 牛客 3 号 | 1500 | 5 | 算法 | 2020-01-01 10:00:00 | -| 4 | 1004 | 牛客 4 号 | 1100 | 4 | 算法 | 2020-01-01 10:00:00 | -| 5 | 1005 | 牛客 5 号 | 1600 | 6 | C++ | 2020-01-01 10:00:00 | -| 6 | 1006 | 牛客 6 号 | 3000 | 6 | C++ | 2020-01-01 10:00:00 | +| id | uid | nick_name | achievement | level | job | register_time | +| --- | ---- | --------- | ----------- | ----- | ---- | ------------------- | +| 1 | 1001 | 牛客 1 号 | 3100 | 7 | 算法 | 2020-01-01 10:00:00 | +| 2 | 1002 | 牛客 2 号 | 2100 | 6 | 算法 | 2020-01-01 10:00:00 | +| 3 | 1003 | 牛客 3 号 | 1500 | 5 | 算法 | 2020-01-01 10:00:00 | +| 4 | 1004 | 牛客 4 号 | 1100 | 4 | 算法 | 2020-01-01 10:00:00 | +| 5 | 1005 | 牛客 5 号 | 1600 | 6 | C++ | 2020-01-01 10:00:00 | +| 6 | 1006 | 牛客 6 号 | 3000 | 6 | C++ | 2020-01-01 10:00:00 | **释义**:用户 1001 昵称为牛客 1 号,成就值为 3100,用户等级是 7 级,职业方向为算法,注册时间 2020-01-01 10:00:00 试卷信息表 `examination_info`(`exam_id` 试卷 ID, `tag` 试卷类别, `difficulty` 试卷难度, `duration` 考试时长, `release_time` 发布时间) 示例数据如下: -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | ---- | ---------- | -------- | ------------------- | -| 1 | 9001 | SQL | hard | 60 | 2021-09-01 06:00:00 | -| 2 | 9002 | C++ | easy | 60 | 2020-02-01 10:00:00 | -| 3 | 9003 | 算法 | medium | 80 | 2020-08-02 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | ---- | ---------- | -------- | ------------------- | +| 1 | 9001 | SQL | hard | 60 | 2021-09-01 06:00:00 | +| 2 | 9002 | C++ | easy | 60 | 2020-02-01 10:00:00 | +| 3 | 9003 | 算法 | medium | 80 | 2020-08-02 10:00:00 | 试卷作答记录表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分) 示例数据如下: -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2021-07-02 09:01:01 | 2021-09-01 09:41:01 | 70 | -| 2 | 1002 | 9003 | 2021-09-01 12:01:01 | 2021-09-01 12:21:01 | 60 | -| 3 | 1002 | 9002 | 2021-09-02 12:01:01 | 2021-09-02 12:31:01 | 70 | -| 4 | 1002 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:40:01 | 80 | -| 5 | 1002 | 9003 | 2021-08-01 12:01:01 | 2021-08-01 12:21:01 | 60 | -| 6 | 1002 | 9002 | 2021-08-02 12:01:01 | 2021-08-02 12:31:01 | 70 | -| 7 | 1002 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:40:01 | 85 | -| 8 | 1002 | 9002 | 2021-07-06 12:01:01 | (NULL) | (NULL) | -| 9 | 1003 | 9002 | 2021-09-07 10:01:01 | 2021-09-07 10:31:01 | 86 | -| 10 | 1003 | 9003 | 2021-09-08 12:01:01 | 2021-09-08 12:11:01 | 40 | -| 11 | 1003 | 9003 | 2021-09-01 13:01:01 | 2021-09-01 13:41:01 | 70 | -| 12 | 1003 | 9001 | 2021-09-08 14:01:01 | (NULL) | (NULL) | -| 13 | 1003 | 9002 | 2021-09-08 15:01:01 | (NULL) | (NULL) | -| 14 | 1005 | 9001 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 90 | -| 15 | 1005 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 88 | -| 16 | 1005 | 9002 | 2021-09-02 12:11:01 | 2021-09-02 12:31:01 | 89 | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2021-07-02 09:01:01 | 2021-09-01 09:41:01 | 70 | +| 2 | 1002 | 9003 | 2021-09-01 12:01:01 | 2021-09-01 12:21:01 | 60 | +| 3 | 1002 | 9002 | 2021-09-02 12:01:01 | 2021-09-02 12:31:01 | 70 | +| 4 | 1002 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:40:01 | 80 | +| 5 | 1002 | 9003 | 2021-08-01 12:01:01 | 2021-08-01 12:21:01 | 60 | +| 6 | 1002 | 9002 | 2021-08-02 12:01:01 | 2021-08-02 12:31:01 | 70 | +| 7 | 1002 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:40:01 | 85 | +| 8 | 1002 | 9002 | 2021-07-06 12:01:01 | (NULL) | (NULL) | +| 9 | 1003 | 9002 | 2021-09-07 10:01:01 | 2021-09-07 10:31:01 | 86 | +| 10 | 1003 | 9003 | 2021-09-08 12:01:01 | 2021-09-08 12:11:01 | 40 | +| 11 | 1003 | 9003 | 2021-09-01 13:01:01 | 2021-09-01 13:41:01 | 70 | +| 12 | 1003 | 9001 | 2021-09-08 14:01:01 | (NULL) | (NULL) | +| 13 | 1003 | 9002 | 2021-09-08 15:01:01 | (NULL) | (NULL) | +| 14 | 1005 | 9001 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 90 | +| 15 | 1005 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 88 | +| 16 | 1005 | 9002 | 2021-09-02 12:11:01 | 2021-09-02 12:31:01 | 89 | 请计算每张 SQL 类别试卷发布后,当天 5 级以上的用户作答的人数 `uv` 和平均分 `avg_score`,按人数降序,相同人数的按平均分升序,示例数据结果输出如下: -| exam_id | uv | avg_score | -| ------- | ---- | --------- | -| 9001 | 3 | 81.3 | +| exam_id | uv | avg_score | +| ------- | --- | --------- | +| 9001 | 3 | 81.3 | 解释:只有一张 SQL 类别的试卷,试卷 ID 为 9001,发布当天(2021-09-01)有 1001、1002、1003、1005 作答过,但是 1003 是 5 级用户,其他 3 位为 5 级以上,他们三的得分有[70,80,85,90],平均分为 81.3(保留 1 位小数)。 @@ -752,43 +752,43 @@ ORDER BY uv DESC, 现有用户信息表 `user_info`(`uid` 用户 ID,`nick_name` 昵称, `achievement` 成就值, `level` 等级, `job` 职业方向, `register_time` 注册时间): -| id | uid | nick_name | achievement | level | job | register_time | -| ---- | ---- | --------- | ----------- | ----- | ---- | ------------------- | -| 1 | 1001 | 牛客 1 号 | 3100 | 7 | 算法 | 2020-01-01 10:00:00 | -| 2 | 1002 | 牛客 2 号 | 2100 | 6 | 算法 | 2020-01-01 10:00:00 | -| 3 | 1003 | 牛客 3 号 | 1500 | 5 | 算法 | 2020-01-01 10:00:00 | -| 4 | 1004 | 牛客 4 号 | 1100 | 4 | 算法 | 2020-01-01 10:00:00 | -| 5 | 1005 | 牛客 5 号 | 1600 | 6 | C++ | 2020-01-01 10:00:00 | -| 6 | 1006 | 牛客 6 号 | 3000 | 6 | C++ | 2020-01-01 10:00:00 | +| id | uid | nick_name | achievement | level | job | register_time | +| --- | ---- | --------- | ----------- | ----- | ---- | ------------------- | +| 1 | 1001 | 牛客 1 号 | 3100 | 7 | 算法 | 2020-01-01 10:00:00 | +| 2 | 1002 | 牛客 2 号 | 2100 | 6 | 算法 | 2020-01-01 10:00:00 | +| 3 | 1003 | 牛客 3 号 | 1500 | 5 | 算法 | 2020-01-01 10:00:00 | +| 4 | 1004 | 牛客 4 号 | 1100 | 4 | 算法 | 2020-01-01 10:00:00 | +| 5 | 1005 | 牛客 5 号 | 1600 | 6 | C++ | 2020-01-01 10:00:00 | +| 6 | 1006 | 牛客 6 号 | 3000 | 6 | C++ | 2020-01-01 10:00:00 | 试卷信息表 `examination_info`(`exam_id` 试卷 ID, `tag` 试卷类别, `difficulty` 试卷难度, `duration` 考试时长, `release_time` 发布时间): -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | ---- | ---------- | -------- | ------------------- | -| 1 | 9001 | SQL | hard | 60 | 2021-09-01 06:00:00 | -| 2 | 9002 | C++ | easy | 60 | 2021-09-01 06:00:00 | -| 3 | 9003 | 算法 | medium | 80 | 2021-09-01 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | ---- | ---------- | -------- | ------------------- | +| 1 | 9001 | SQL | hard | 60 | 2021-09-01 06:00:00 | +| 2 | 9002 | C++ | easy | 60 | 2021-09-01 06:00:00 | +| 3 | 9003 | 算法 | medium | 80 | 2021-09-01 10:00:00 | 试卷作答信息表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2021-09-01 09:01:01 | 2021-09-01 09:41:01 | 79 | -| 2 | 1002 | 9003 | 2021-09-01 12:01:01 | 2021-09-01 12:21:01 | 60 | -| 3 | 1002 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 70 | -| 4 | 1002 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:40:01 | 80 | -| 5 | 1002 | 9003 | 2021-08-01 12:01:01 | 2021-08-01 12:21:01 | 60 | -| 6 | 1002 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 70 | -| 7 | 1002 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:40:01 | 85 | -| 8 | 1002 | 9002 | 2021-09-01 12:01:01 | (NULL) | (NULL) | -| 9 | 1003 | 9002 | 2021-09-07 10:01:01 | 2021-09-07 10:31:01 | 86 | -| 10 | 1003 | 9003 | 2021-09-08 12:01:01 | 2021-09-08 12:11:01 | 40 | -| 11 | 1003 | 9003 | 2021-09-01 13:01:01 | 2021-09-01 13:41:01 | 81 | -| 12 | 1003 | 9001 | 2021-09-01 14:01:01 | (NULL) | (NULL) | -| 13 | 1003 | 9002 | 2021-09-08 15:01:01 | (NULL) | (NULL) | -| 14 | 1005 | 9001 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 90 | -| 15 | 1005 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 88 | -| 16 | 1005 | 9002 | 2021-09-02 12:11:01 | 2021-09-02 12:31:01 | 89 | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2021-09-01 09:01:01 | 2021-09-01 09:41:01 | 79 | +| 2 | 1002 | 9003 | 2021-09-01 12:01:01 | 2021-09-01 12:21:01 | 60 | +| 3 | 1002 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 70 | +| 4 | 1002 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:40:01 | 80 | +| 5 | 1002 | 9003 | 2021-08-01 12:01:01 | 2021-08-01 12:21:01 | 60 | +| 6 | 1002 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 70 | +| 7 | 1002 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:40:01 | 85 | +| 8 | 1002 | 9002 | 2021-09-01 12:01:01 | (NULL) | (NULL) | +| 9 | 1003 | 9002 | 2021-09-07 10:01:01 | 2021-09-07 10:31:01 | 86 | +| 10 | 1003 | 9003 | 2021-09-08 12:01:01 | 2021-09-08 12:11:01 | 40 | +| 11 | 1003 | 9003 | 2021-09-01 13:01:01 | 2021-09-01 13:41:01 | 81 | +| 12 | 1003 | 9001 | 2021-09-01 14:01:01 | (NULL) | (NULL) | +| 13 | 1003 | 9002 | 2021-09-08 15:01:01 | (NULL) | (NULL) | +| 14 | 1005 | 9001 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 90 | +| 15 | 1005 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 88 | +| 16 | 1005 | 9002 | 2021-09-02 12:11:01 | 2021-09-02 12:31:01 | 89 | 统计作答 SQL 类别的试卷得分大于过 80 的人的用户等级分布,按数量降序排序(保证数量都不同)。示例数据结果输出如下: @@ -826,35 +826,35 @@ ORDER BY level_cnt DESC 现有试卷作答记录表 exam_record(uid 用户 ID, exam_id 试卷 ID, start_time 开始作答时间, submit_time 交卷时间, score 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2021-09-01 09:01:01 | 2021-09-01 09:41:01 | 81 | -| 2 | 1002 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 70 | -| 3 | 1002 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:40:01 | 80 | -| 4 | 1002 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 70 | -| 5 | 1004 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:40:01 | 85 | -| 6 | 1002 | 9002 | 2021-09-01 12:01:01 | (NULL) | (NULL) | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2021-09-01 09:01:01 | 2021-09-01 09:41:01 | 81 | +| 2 | 1002 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 70 | +| 3 | 1002 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:40:01 | 80 | +| 4 | 1002 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 70 | +| 5 | 1004 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:40:01 | 85 | +| 6 | 1002 | 9002 | 2021-09-01 12:01:01 | (NULL) | (NULL) | 题目练习表 practice_record(uid 用户 ID, question_id 题目 ID, submit_time 提交时间, score 得分): -| id | uid | question_id | submit_time | score | -| ---- | ---- | ----------- | ------------------- | ----- | -| 1 | 1001 | 8001 | 2021-08-02 11:41:01 | 60 | -| 2 | 1002 | 8001 | 2021-09-02 19:30:01 | 50 | -| 3 | 1002 | 8001 | 2021-09-02 19:20:01 | 70 | -| 4 | 1002 | 8002 | 2021-09-02 19:38:01 | 70 | -| 5 | 1003 | 8001 | 2021-08-02 19:38:01 | 70 | -| 6 | 1003 | 8001 | 2021-08-02 19:48:01 | 90 | -| 7 | 1003 | 8002 | 2021-08-01 19:38:01 | 80 | +| id | uid | question_id | submit_time | score | +| --- | ---- | ----------- | ------------------- | ----- | +| 1 | 1001 | 8001 | 2021-08-02 11:41:01 | 60 | +| 2 | 1002 | 8001 | 2021-09-02 19:30:01 | 50 | +| 3 | 1002 | 8001 | 2021-09-02 19:20:01 | 70 | +| 4 | 1002 | 8002 | 2021-09-02 19:38:01 | 70 | +| 5 | 1003 | 8001 | 2021-08-02 19:38:01 | 70 | +| 6 | 1003 | 8001 | 2021-08-02 19:48:01 | 90 | +| 7 | 1003 | 8002 | 2021-08-01 19:38:01 | 80 | 请统计每个题目和每份试卷被作答的人数和次数,分别按照"试卷"和"题目"的 uv & pv 降序显示,示例数据结果输出如下: -| tid | uv | pv | -| ---- | ---- | ---- | -| 9001 | 3 | 3 | -| 9002 | 1 | 3 | -| 8001 | 3 | 5 | -| 8002 | 2 | 2 | +| tid | uv | pv | +| ---- | --- | --- | +| 9001 | 3 | 3 | +| 9002 | 1 | 3 | +| 8001 | 3 | 5 | +| 8002 | 2 | 2 | **解释**:“试卷”有 3 人共练习 3 次试卷 9001,1 人作答 3 次 9002;“刷题”有 3 人刷 5 次 8001,有 2 人刷 2 次 8002 @@ -918,21 +918,21 @@ FROM 现有试卷信息表 `examination_info`(`exam_id` 试卷 ID, `tag` 试卷类别, `difficulty` 试卷难度, `duration` 考试时长, `release_time` 发布时间): -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | ---- | ---------- | -------- | ------------------- | -| 1 | 9001 | SQL | hard | 60 | 2021-09-01 06:00:00 | -| 2 | 9002 | C++ | easy | 60 | 2021-09-01 06:00:00 | -| 3 | 9003 | 算法 | medium | 80 | 2021-09-01 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | ---- | ---------- | -------- | ------------------- | +| 1 | 9001 | SQL | hard | 60 | 2021-09-01 06:00:00 | +| 2 | 9002 | C++ | easy | 60 | 2021-09-01 06:00:00 | +| 3 | 9003 | 算法 | medium | 80 | 2021-09-01 10:00:00 | 试卷作答记录表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2021-09-01 09:01:01 | 2021-09-01 09:31:00 | 81 | -| 2 | 1002 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 70 | -| 3 | 1003 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:40:01 | **86** | -| 4 | 1003 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 89 | -| 5 | 1004 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:30:01 | 85 | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2021-09-01 09:01:01 | 2021-09-01 09:31:00 | 81 | +| 2 | 1002 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 70 | +| 3 | 1003 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:40:01 | **86** | +| 4 | 1003 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 89 | +| 5 | 1004 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:30:01 | 85 | 示例数据输出结果: @@ -1011,52 +1011,52 @@ ORDER BY UID 现有用户信息表 user_info(uid 用户 ID,nick_name 昵称, achievement 成就值, level 等级, job 职业方向, register_time 注册时间): -| id | uid | nick_name | achievement | level | job | register_time | -| ---- | ---- | --------- | ----------- | ----- | ---- | ------------------- | -| 1 | 1001 | 牛客 1 号 | 3100 | 7 | 算法 | 2020-01-01 10:00:00 | -| 2 | 1002 | 牛客 2 号 | 2300 | 7 | 算法 | 2020-01-01 10:00:00 | -| 3 | 1003 | 牛客 3 号 | 2500 | 7 | 算法 | 2020-01-01 10:00:00 | -| 4 | 1004 | 牛客 4 号 | 1200 | 5 | 算法 | 2020-01-01 10:00:00 | -| 5 | 1005 | 牛客 5 号 | 1600 | 6 | C++ | 2020-01-01 10:00:00 | -| 6 | 1006 | 牛客 6 号 | 2000 | 6 | C++ | 2020-01-01 10:00:00 | +| id | uid | nick_name | achievement | level | job | register_time | +| --- | ---- | --------- | ----------- | ----- | ---- | ------------------- | +| 1 | 1001 | 牛客 1 号 | 3100 | 7 | 算法 | 2020-01-01 10:00:00 | +| 2 | 1002 | 牛客 2 号 | 2300 | 7 | 算法 | 2020-01-01 10:00:00 | +| 3 | 1003 | 牛客 3 号 | 2500 | 7 | 算法 | 2020-01-01 10:00:00 | +| 4 | 1004 | 牛客 4 号 | 1200 | 5 | 算法 | 2020-01-01 10:00:00 | +| 5 | 1005 | 牛客 5 号 | 1600 | 6 | C++ | 2020-01-01 10:00:00 | +| 6 | 1006 | 牛客 6 号 | 2000 | 6 | C++ | 2020-01-01 10:00:00 | 试卷信息表 examination_info(exam_id 试卷 ID, tag 试卷类别, difficulty 试卷难度, duration 考试时长, release_time 发布时间): -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | ---- | ---------- | -------- | ------------------- | -| 1 | 9001 | SQL | hard | 60 | 2021-09-01 06:00:00 | -| 2 | 9002 | C++ | hard | 60 | 2021-09-01 06:00:00 | -| 3 | 9003 | 算法 | medium | 80 | 2021-09-01 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | ---- | ---------- | -------- | ------------------- | +| 1 | 9001 | SQL | hard | 60 | 2021-09-01 06:00:00 | +| 2 | 9002 | C++ | hard | 60 | 2021-09-01 06:00:00 | +| 3 | 9003 | 算法 | medium | 80 | 2021-09-01 10:00:00 | 试卷作答记录表 exam_record(uid 用户 ID, exam_id 试卷 ID, start_time 开始作答时间, submit_time 交卷时间, score 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ----- | -| 1 | 1001 | 9001 | 2021-09-01 09:01:01 | 2021-09-01 09:31:00 | 81 | -| 2 | 1002 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 81 | -| 3 | 1003 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:40:01 | 86 | -| 4 | 1003 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:51 | 89 | -| 5 | 1004 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:30:01 | 85 | -| 6 | 1005 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:02 | 85 | -| 7 | 1006 | 9003 | 2021-09-07 10:01:01 | 2021-09-07 10:21:01 | 84 | -| 8 | 1006 | 9001 | 2021-09-07 10:01:01 | 2021-09-07 10:21:01 | 80 | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ----- | +| 1 | 1001 | 9001 | 2021-09-01 09:01:01 | 2021-09-01 09:31:00 | 81 | +| 2 | 1002 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 81 | +| 3 | 1003 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:40:01 | 86 | +| 4 | 1003 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:51 | 89 | +| 5 | 1004 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:30:01 | 85 | +| 6 | 1005 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:02 | 85 | +| 7 | 1006 | 9003 | 2021-09-07 10:01:01 | 2021-09-07 10:21:01 | 84 | +| 8 | 1006 | 9001 | 2021-09-07 10:01:01 | 2021-09-07 10:21:01 | 80 | 题目练习记录表 practice_record(uid 用户 ID, question_id 题目 ID, submit_time 提交时间, score 得分): -| id | uid | question_id | submit_time | score | -| ---- | ---- | ----------- | ------------------- | ----- | -| 1 | 1001 | 8001 | 2021-08-02 11:41:01 | 60 | -| 2 | 1002 | 8001 | 2021-09-02 19:30:01 | 50 | -| 3 | 1002 | 8001 | 2021-09-02 19:20:01 | 70 | -| 4 | 1002 | 8002 | 2021-09-02 19:38:01 | 70 | -| 5 | 1004 | 8001 | 2021-08-02 19:38:01 | 70 | -| 6 | 1004 | 8002 | 2021-08-02 19:48:01 | 90 | -| 7 | 1001 | 8002 | 2021-08-02 19:38:01 | 70 | -| 8 | 1004 | 8002 | 2021-08-02 19:48:01 | 90 | -| 9 | 1004 | 8002 | 2021-08-02 19:58:01 | 94 | -| 10 | 1004 | 8003 | 2021-08-02 19:38:01 | 70 | -| 11 | 1004 | 8003 | 2021-08-02 19:48:01 | 90 | -| 12 | 1004 | 8003 | 2021-08-01 19:38:01 | 80 | +| id | uid | question_id | submit_time | score | +| --- | ---- | ----------- | ------------------- | ----- | +| 1 | 1001 | 8001 | 2021-08-02 11:41:01 | 60 | +| 2 | 1002 | 8001 | 2021-09-02 19:30:01 | 50 | +| 3 | 1002 | 8001 | 2021-09-02 19:20:01 | 70 | +| 4 | 1002 | 8002 | 2021-09-02 19:38:01 | 70 | +| 5 | 1004 | 8001 | 2021-08-02 19:38:01 | 70 | +| 6 | 1004 | 8002 | 2021-08-02 19:48:01 | 90 | +| 7 | 1001 | 8002 | 2021-08-02 19:38:01 | 70 | +| 8 | 1004 | 8002 | 2021-08-02 19:48:01 | 90 | +| 9 | 1004 | 8002 | 2021-08-02 19:58:01 | 94 | +| 10 | 1004 | 8003 | 2021-08-02 19:38:01 | 70 | +| 11 | 1004 | 8003 | 2021-08-02 19:48:01 | 90 | +| 12 | 1004 | 8003 | 2021-08-01 19:38:01 | 80 | 请你找到高难度 SQL 试卷得分平均值大于 80 并且是 7 级的红名大佬,统计他们的 2021 年试卷总完成次数和题目总练习次数,只保留 2021 年有试卷完成记录的用户。结果按试卷完成数升序,按题目练习数降序。 @@ -1126,22 +1126,22 @@ ORDER BY exam_cnt, 现有用户信息表 `user_info`(`uid` 用户 ID,`nick_name` 昵称, `achievement` 成就值, `level` 等级, `job` 职业方向, `register_time` 注册时间): -| id | uid | nick_name | achievement | level | job | register_time | -| ---- | ---- | --------- | ----------- | ----- | ---- | ------------------- | -| 1 | 1001 | 牛客 1 号 | 3100 | 7 | 算法 | 2020-01-01 10:00:00 | -| 2 | 1002 | 牛客 2 号 | 2300 | 7 | 算法 | 2020-01-01 10:00:00 | -| 3 | 1003 | 牛客 3 号 | 2500 | 7 | 算法 | 2020-01-01 10:00:00 | -| 4 | 1004 | 牛客 4 号 | 1200 | 5 | 算法 | 2020-01-01 10:00:00 | -| 5 | 1005 | 牛客 5 号 | 1600 | 6 | C++ | 2020-01-01 10:00:00 | -| 6 | 1006 | 牛客 6 号 | 2600 | 7 | C++ | 2020-01-01 10:00:00 | +| id | uid | nick_name | achievement | level | job | register_time | +| --- | ---- | --------- | ----------- | ----- | ---- | ------------------- | +| 1 | 1001 | 牛客 1 号 | 3100 | 7 | 算法 | 2020-01-01 10:00:00 | +| 2 | 1002 | 牛客 2 号 | 2300 | 7 | 算法 | 2020-01-01 10:00:00 | +| 3 | 1003 | 牛客 3 号 | 2500 | 7 | 算法 | 2020-01-01 10:00:00 | +| 4 | 1004 | 牛客 4 号 | 1200 | 5 | 算法 | 2020-01-01 10:00:00 | +| 5 | 1005 | 牛客 5 号 | 1600 | 6 | C++ | 2020-01-01 10:00:00 | +| 6 | 1006 | 牛客 6 号 | 2600 | 7 | C++ | 2020-01-01 10:00:00 | 试卷信息表 `examination_info`(`exam_id` 试卷 ID, `tag` 试卷类别, `difficulty` 试卷难度, `duration` 考试时长, `release_time` 发布时间): -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | ---- | ---------- | -------- | ------------------- | -| 1 | 9001 | SQL | hard | 60 | 2021-09-01 06:00:00 | -| 2 | 9002 | C++ | easy | 60 | 2021-09-01 06:00:00 | -| 3 | 9003 | 算法 | medium | 80 | 2021-09-01 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | ---- | ---------- | -------- | ------------------- | +| 1 | 9001 | SQL | hard | 60 | 2021-09-01 06:00:00 | +| 2 | 9002 | C++ | easy | 60 | 2021-09-01 06:00:00 | +| 3 | 9003 | 算法 | medium | 80 | 2021-09-01 10:00:00 | 试卷作答记录表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分): @@ -1298,4 +1298,4 @@ ORDER BY act_month_total DESC, act_days_2021 DESC ``` - \ No newline at end of file + diff --git a/docs/database/sql/sql-questions-04.md b/docs/database/sql/sql-questions-04.md index 0aa3d8e5..c15eb8e2 100644 --- a/docs/database/sql/sql-questions-04.md +++ b/docs/database/sql/sql-questions-04.md @@ -73,26 +73,26 @@ FROM table; 现有试卷信息表 `examination_info`(`exam_id` 试卷 ID, `tag` 试卷类别, `difficulty` 试卷难度, `duration` 考试时长, `release_time` 发布时间): -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | ---- | ---------- | -------- | ------------------- | -| 1 | 9001 | SQL | hard | 60 | 2021-09-01 06:00:00 | -| 2 | 9002 | SQL | hard | 60 | 2021-09-01 06:00:00 | -| 3 | 9003 | 算法 | medium | 80 | 2021-09-01 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | ---- | ---------- | -------- | ------------------- | +| 1 | 9001 | SQL | hard | 60 | 2021-09-01 06:00:00 | +| 2 | 9002 | SQL | hard | 60 | 2021-09-01 06:00:00 | +| 3 | 9003 | 算法 | medium | 80 | 2021-09-01 10:00:00 | 试卷作答记录表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, score 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2021-09-01 09:01:01 | 2021-09-01 09:31:00 | 78 | -| 2 | 1002 | 9001 | 2021-09-01 09:01:01 | 2021-09-01 09:31:00 | 81 | -| 3 | 1002 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 81 | -| 4 | 1003 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:40:01 | 86 | -| 5 | 1003 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:51 | 89 | -| 6 | 1004 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:30:01 | 85 | -| 7 | 1005 | 9003 | 2021-09-01 12:01:01 | 2021-09-01 12:31:02 | 85 | -| 8 | 1006 | 9003 | 2021-09-07 10:01:01 | 2021-09-07 10:21:01 | 84 | -| 9 | 1003 | 9003 | 2021-09-08 12:01:01 | 2021-09-08 12:11:01 | 40 | -| 10 | 1003 | 9002 | 2021-09-01 14:01:01 | (NULL) | (NULL) | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2021-09-01 09:01:01 | 2021-09-01 09:31:00 | 78 | +| 2 | 1002 | 9001 | 2021-09-01 09:01:01 | 2021-09-01 09:31:00 | 81 | +| 3 | 1002 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 81 | +| 4 | 1003 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:40:01 | 86 | +| 5 | 1003 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:51 | 89 | +| 6 | 1004 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:30:01 | 85 | +| 7 | 1005 | 9003 | 2021-09-01 12:01:01 | 2021-09-01 12:31:02 | 85 | +| 8 | 1006 | 9003 | 2021-09-07 10:01:01 | 2021-09-07 10:21:01 | 84 | +| 9 | 1003 | 9003 | 2021-09-08 12:01:01 | 2021-09-08 12:11:01 | 40 | +| 10 | 1003 | 9002 | 2021-09-01 14:01:01 | (NULL) | (NULL) | 找到每类试卷得分的前 3 名,如果两人最大分数相同,选择最小分数大者,如果还相同,选择 uid 大者。由示例数据结果输出如下: @@ -118,8 +118,8 @@ FROM a.uid AS UID, ROW_NUMBER() OVER (PARTITION BY b.tag ORDER BY b.tag, - max(a.score) DESC, - min(a.score) DESC, + max(a.score) DESC, + min(a.score) DESC, a.uid DESC) AS ranking FROM exam_record a LEFT JOIN examination_info b ON a.exam_id = b.exam_id @@ -134,28 +134,28 @@ WHERE ranking <= 3 现有试卷信息表 `examination_info`(`exam_id` 试卷 ID, `tag` 试卷类别, `difficulty` 试卷难度, `duration` 考试时长, `release_time` 发布时间): -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | ---- | ---------- | -------- | ------------------- | -| 1 | 9001 | SQL | hard | 60 | 2021-09-01 06:00:00 | -| 2 | 9002 | C++ | hard | 60 | 2021-09-01 06:00:00 | -| 3 | 9003 | 算法 | medium | 80 | 2021-09-01 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | ---- | ---------- | -------- | ------------------- | +| 1 | 9001 | SQL | hard | 60 | 2021-09-01 06:00:00 | +| 2 | 9002 | C++ | hard | 60 | 2021-09-01 06:00:00 | +| 3 | 9003 | 算法 | medium | 80 | 2021-09-01 10:00:00 | 试卷作答记录表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2021-09-01 09:01:01 | 2021-09-01 09:51:01 | 78 | -| 2 | 1001 | 9002 | 2021-09-01 09:01:01 | 2021-09-01 09:31:00 | 81 | -| 3 | 1002 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 81 | -| 4 | 1003 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:59:01 | 86 | -| 5 | 1003 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:51 | 89 | -| 6 | 1004 | 9002 | 2021-09-01 19:01:01 | 2021-09-01 19:30:01 | 85 | -| 7 | 1005 | 9001 | 2021-09-01 12:01:01 | 2021-09-01 12:31:02 | 85 | -| 8 | 1006 | 9001 | 2021-09-07 10:01:01 | 2021-09-07 10:21:01 | 84 | -| 9 | 1003 | 9001 | 2021-09-08 12:01:01 | 2021-09-08 12:11:01 | 40 | -| 10 | 1003 | 9002 | 2021-09-01 14:01:01 | (NULL) | (NULL) | -| 11 | 1005 | 9001 | 2021-09-01 14:01:01 | (NULL) | (NULL) | -| 12 | 1003 | 9003 | 2021-09-08 15:01:01 | (NULL) | (NULL) | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2021-09-01 09:01:01 | 2021-09-01 09:51:01 | 78 | +| 2 | 1001 | 9002 | 2021-09-01 09:01:01 | 2021-09-01 09:31:00 | 81 | +| 3 | 1002 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:01 | 81 | +| 4 | 1003 | 9001 | 2021-09-01 19:01:01 | 2021-09-01 19:59:01 | 86 | +| 5 | 1003 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:31:51 | 89 | +| 6 | 1004 | 9002 | 2021-09-01 19:01:01 | 2021-09-01 19:30:01 | 85 | +| 7 | 1005 | 9001 | 2021-09-01 12:01:01 | 2021-09-01 12:31:02 | 85 | +| 8 | 1006 | 9001 | 2021-09-07 10:01:01 | 2021-09-07 10:21:01 | 84 | +| 9 | 1003 | 9001 | 2021-09-08 12:01:01 | 2021-09-08 12:11:01 | 40 | +| 10 | 1003 | 9002 | 2021-09-01 14:01:01 | (NULL) | (NULL) | +| 11 | 1005 | 9001 | 2021-09-01 14:01:01 | (NULL) | (NULL) | +| 12 | 1003 | 9003 | 2021-09-08 15:01:01 | (NULL) | (NULL) | 找到第二快和第二慢用时之差大于试卷时长的一半的试卷信息,按试卷 ID 降序排序。由示例数据结果输出如下: @@ -198,13 +198,13 @@ ORDER BY a.exam_id DESC 现有试卷作答记录表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ----- | -| 1 | 1006 | 9003 | 2021-09-07 10:01:01 | 2021-09-07 10:21:02 | 84 | -| 2 | 1006 | 9001 | 2021-09-01 12:11:01 | 2021-09-01 12:31:01 | 89 | -| 3 | 1006 | 9002 | 2021-09-06 10:01:01 | 2021-09-06 10:21:01 | 81 | -| 4 | 1005 | 9002 | 2021-09-05 10:01:01 | 2021-09-05 10:21:01 | 81 | -| 5 | 1005 | 9001 | 2021-09-05 10:31:01 | 2021-09-05 10:51:01 | 81 | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ----- | +| 1 | 1006 | 9003 | 2021-09-07 10:01:01 | 2021-09-07 10:21:02 | 84 | +| 2 | 1006 | 9001 | 2021-09-01 12:11:01 | 2021-09-01 12:31:01 | 89 | +| 3 | 1006 | 9002 | 2021-09-06 10:01:01 | 2021-09-06 10:21:01 | 81 | +| 4 | 1005 | 9002 | 2021-09-05 10:01:01 | 2021-09-05 10:21:01 | 81 | +| 5 | 1005 | 9001 | 2021-09-05 10:31:01 | 2021-09-05 10:51:01 | 81 | 请计算在 2021 年至少有两天作答过试卷的人中,计算该年连续两次作答试卷的最大时间窗 `days_window`,那么根据该年的历史规律他在 `days_window` 天里平均会做多少套试卷,按最大时间窗和平均做答试卷套数倒序排序。由示例数据结果输出如下: @@ -245,18 +245,18 @@ ORDER BY days_window DESC, 现有试卷作答记录表 `exam_record`(`uid`:用户 ID, `exam_id`:试卷 ID, `start_time`:开始作答时间, `submit_time`:交卷时间,为空的话则代表未完成, `score`:得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1006 | 9003 | 2021-09-06 10:01:01 | 2021-09-06 10:21:02 | 84 | -| 2 | 1006 | 9001 | 2021-08-02 12:11:01 | 2021-08-02 12:31:01 | 89 | -| 3 | 1006 | 9002 | 2021-06-06 10:01:01 | 2021-06-06 10:21:01 | 81 | -| 4 | 1006 | 9002 | 2021-05-06 10:01:01 | 2021-05-06 10:21:01 | 81 | -| 5 | 1006 | 9001 | 2021-05-01 12:01:01 | (NULL) | (NULL) | -| 6 | 1001 | 9001 | 2021-09-05 10:31:01 | 2021-09-05 10:51:01 | 81 | -| 7 | 1001 | 9003 | 2021-08-01 09:01:01 | 2021-08-01 09:51:11 | 78 | -| 8 | 1001 | 9002 | 2021-07-01 09:01:01 | 2021-07-01 09:31:00 | 81 | -| 9 | 1001 | 9002 | 2021-07-01 12:01:01 | 2021-07-01 12:31:01 | 81 | -| 10 | 1001 | 9002 | 2021-07-01 12:01:01 | (NULL) | (NULL) | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1006 | 9003 | 2021-09-06 10:01:01 | 2021-09-06 10:21:02 | 84 | +| 2 | 1006 | 9001 | 2021-08-02 12:11:01 | 2021-08-02 12:31:01 | 89 | +| 3 | 1006 | 9002 | 2021-06-06 10:01:01 | 2021-06-06 10:21:01 | 81 | +| 4 | 1006 | 9002 | 2021-05-06 10:01:01 | 2021-05-06 10:21:01 | 81 | +| 5 | 1006 | 9001 | 2021-05-01 12:01:01 | (NULL) | (NULL) | +| 6 | 1001 | 9001 | 2021-09-05 10:31:01 | 2021-09-05 10:51:01 | 81 | +| 7 | 1001 | 9003 | 2021-08-01 09:01:01 | 2021-08-01 09:51:11 | 78 | +| 8 | 1001 | 9002 | 2021-07-01 09:01:01 | 2021-07-01 09:31:00 | 81 | +| 9 | 1001 | 9002 | 2021-07-01 12:01:01 | 2021-07-01 12:31:01 | 81 | +| 10 | 1001 | 9002 | 2021-07-01 12:01:01 | (NULL) | (NULL) | 找到每个人近三个有试卷作答记录的月份中没有试卷是未完成状态的用户的试卷作答完成数,按试卷完成数和用户 ID 降序排名。由示例数据结果输出如下: @@ -296,42 +296,42 @@ ORDER BY exam_complete_cnt DESC, 现有用户信息表 `user_info`(`uid` 用户 ID,`nick_name` 昵称, `achievement` 成就值, `level` 等级, `job` 职业方向, `register_time` 注册时间): -| id | uid | nick_name | achievement | level | job | register_time | -| ---- | ---- | ----------- | ----------- | ----- | ---- | ------------------- | -| 1 | 1001 | 牛客 1 号 | 3200 | 7 | 算法 | 2020-01-01 10:00:00 | -| 2 | 1002 | 牛客 2 号 | 2500 | 6 | 算法 | 2020-01-01 10:00:00 | -| 3 | 1003 | 牛客 3 号 ♂ | 2200 | 5 | 算法 | 2020-01-01 10:00:00 | +| id | uid | nick_name | achievement | level | job | register_time | +| --- | ---- | ------------ | ----------- | ----- | ---- | ------------------- | +| 1 | 1001 | 牛客 1 号 | 3200 | 7 | 算法 | 2020-01-01 10:00:00 | +| 2 | 1002 | 牛客 2 号 | 2500 | 6 | 算法 | 2020-01-01 10:00:00 | +| 3 | 1003 | 牛客 3 号 ♂ | 2200 | 5 | 算法 | 2020-01-01 10:00:00 | 试卷信息表 `examination_info`(`exam_id` 试卷 ID, `tag` 试卷类别, `difficulty` 试卷难度, `duration` 考试时长, `release_time` 发布时间): -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | ------ | ---------- | -------- | ------------------- | -| 1 | 9001 | SQL | hard | 60 | 2020-01-01 10:00:00 | -| 2 | 9002 | SQL | hard | 80 | 2020-01-01 10:00:00 | -| 3 | 9003 | 算法 | hard | 80 | 2020-01-01 10:00:00 | -| 4 | 9004 | PYTHON | medium | 70 | 2020-01-01 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | ------ | ---------- | -------- | ------------------- | +| 1 | 9001 | SQL | hard | 60 | 2020-01-01 10:00:00 | +| 2 | 9002 | SQL | hard | 80 | 2020-01-01 10:00:00 | +| 3 | 9003 | 算法 | hard | 80 | 2020-01-01 10:00:00 | +| 4 | 9004 | PYTHON | medium | 70 | 2020-01-01 10:00:00 | 试卷作答记录表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ----- | -| 1 | 1001 | 9001 | 2020-01-01 09:01:01 | 2020-01-01 09:21:59 | 90 | -| 15 | 1002 | 9001 | 2020-01-01 18:01:01 | 2020-01-01 18:59:02 | 90 | -| 13 | 1001 | 9001 | 2020-01-02 10:01:01 | 2020-01-02 10:31:01 | 89 | -| 2 | 1002 | 9001 | 2020-01-20 10:01:01 | | | -| 3 | 1002 | 9001 | 2020-02-01 12:11:01 | | | -| 5 | 1001 | 9001 | 2020-03-01 12:01:01 | | | -| 6 | 1002 | 9001 | 2020-03-01 12:01:01 | 2020-03-01 12:41:01 | 90 | -| 4 | 1003 | 9001 | 2020-03-01 19:01:01 | | | -| 7 | 1002 | 9001 | 2020-05-02 19:01:01 | 2020-05-02 19:32:00 | 90 | -| 14 | 1001 | 9002 | 2020-01-01 12:11:01 | | | -| 8 | 1001 | 9002 | 2020-01-02 19:01:01 | 2020-01-02 19:59:01 | 69 | -| 9 | 1001 | 9002 | 2020-02-02 12:01:01 | 2020-02-02 12:20:01 | 99 | -| 10 | 1002 | 9002 | 2020-02-02 12:01:01 | | | -| 11 | 1002 | 9002 | 2020-02-02 12:01:01 | 2020-02-02 12:43:01 | 81 | -| 12 | 1002 | 9002 | 2020-03-02 12:11:01 | | | -| 17 | 1001 | 9002 | 2020-05-05 18:01:01 | | | -| 16 | 1002 | 9003 | 2020-05-06 12:01:01 | | | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ----- | +| 1 | 1001 | 9001 | 2020-01-01 09:01:01 | 2020-01-01 09:21:59 | 90 | +| 15 | 1002 | 9001 | 2020-01-01 18:01:01 | 2020-01-01 18:59:02 | 90 | +| 13 | 1001 | 9001 | 2020-01-02 10:01:01 | 2020-01-02 10:31:01 | 89 | +| 2 | 1002 | 9001 | 2020-01-20 10:01:01 | | | +| 3 | 1002 | 9001 | 2020-02-01 12:11:01 | | | +| 5 | 1001 | 9001 | 2020-03-01 12:01:01 | | | +| 6 | 1002 | 9001 | 2020-03-01 12:01:01 | 2020-03-01 12:41:01 | 90 | +| 4 | 1003 | 9001 | 2020-03-01 19:01:01 | | | +| 7 | 1002 | 9001 | 2020-05-02 19:01:01 | 2020-05-02 19:32:00 | 90 | +| 14 | 1001 | 9002 | 2020-01-01 12:11:01 | | | +| 8 | 1001 | 9002 | 2020-01-02 19:01:01 | 2020-01-02 19:59:01 | 69 | +| 9 | 1001 | 9002 | 2020-02-02 12:01:01 | 2020-02-02 12:20:01 | 99 | +| 10 | 1002 | 9002 | 2020-02-02 12:01:01 | | | +| 11 | 1002 | 9002 | 2020-02-02 12:01:01 | 2020-02-02 12:43:01 | 81 | +| 12 | 1002 | 9002 | 2020-03-02 12:11:01 | | | +| 17 | 1001 | 9002 | 2020-05-05 18:01:01 | | | +| 16 | 1002 | 9003 | 2020-05-06 12:01:01 | | | 请统计 SQL 试卷上未完成率较高的 50%用户中,6 级和 7 级用户在有试卷作答记录的近三个月中,每个月的答卷数目和完成数目。按用户 ID、月份升序排序。 @@ -434,43 +434,43 @@ ORDER BY t1.uid, 现有试卷信息表 `examination_info`(`exam_id` 试卷 ID, `tag` 试卷类别, `difficulty` 试卷难度, `duration` 考试时长, `release_time` 发布时间): -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | ------ | ---------- | -------- | ------------------- | -| 1 | 9001 | SQL | hard | 60 | 2021-01-01 10:00:00 | -| 2 | 9002 | C++ | hard | 80 | 2021-01-01 10:00:00 | -| 3 | 9003 | 算法 | hard | 80 | 2021-01-01 10:00:00 | -| 4 | 9004 | PYTHON | medium | 70 | 2021-01-01 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | ------ | ---------- | -------- | ------------------- | +| 1 | 9001 | SQL | hard | 60 | 2021-01-01 10:00:00 | +| 2 | 9002 | C++ | hard | 80 | 2021-01-01 10:00:00 | +| 3 | 9003 | 算法 | hard | 80 | 2021-01-01 10:00:00 | +| 4 | 9004 | PYTHON | medium | 70 | 2021-01-01 10:00:00 | 试卷作答记录表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ----- | -| 1 | 1001 | 9001 | 2020-08-02 10:01:01 | 2020-08-02 10:31:01 | 89 | -| 2 | 1002 | 9001 | 2020-04-01 18:01:01 | 2020-04-01 18:59:02 | 90 | -| 3 | 1001 | 9001 | 2020-04-01 09:01:01 | 2020-04-01 09:21:59 | 80 | -| 5 | 1002 | 9001 | 2021-03-02 19:01:01 | 2021-03-02 19:32:00 | 20 | -| 8 | 1003 | 9001 | 2021-05-02 12:01:01 | 2021-05-02 12:31:01 | 98 | -| 13 | 1003 | 9001 | 2020-01-02 10:01:01 | 2020-01-02 10:31:01 | 89 | -| 9 | 1001 | 9002 | 2020-02-02 12:01:01 | 2020-02-02 12:20:01 | 99 | -| 10 | 1002 | 9002 | 2021-02-02 12:01:01 | 2020-02-02 12:43:01 | 81 | -| 11 | 1001 | 9002 | 2020-01-02 19:01:01 | 2020-01-02 19:59:01 | 69 | -| 16 | 1002 | 9002 | 2020-02-02 12:01:01 | | | -| 17 | 1002 | 9002 | 2020-03-02 12:11:01 | | | -| 18 | 1001 | 9002 | 2021-05-05 18:01:01 | | | -| 4 | 1002 | 9003 | 2021-01-20 10:01:01 | 2021-01-20 10:10:01 | 81 | -| 6 | 1001 | 9003 | 2021-04-02 19:01:01 | 2021-04-02 19:40:01 | 89 | -| 15 | 1002 | 9003 | 2021-01-01 18:01:01 | 2021-01-01 18:59:02 | 90 | -| 7 | 1004 | 9004 | 2020-05-02 12:01:01 | 2020-05-02 12:20:01 | 99 | -| 12 | 1001 | 9004 | 2021-09-02 12:11:01 | | | -| 14 | 1002 | 9004 | 2020-01-01 12:11:01 | 2020-01-01 12:31:01 | 83 | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ----- | +| 1 | 1001 | 9001 | 2020-08-02 10:01:01 | 2020-08-02 10:31:01 | 89 | +| 2 | 1002 | 9001 | 2020-04-01 18:01:01 | 2020-04-01 18:59:02 | 90 | +| 3 | 1001 | 9001 | 2020-04-01 09:01:01 | 2020-04-01 09:21:59 | 80 | +| 5 | 1002 | 9001 | 2021-03-02 19:01:01 | 2021-03-02 19:32:00 | 20 | +| 8 | 1003 | 9001 | 2021-05-02 12:01:01 | 2021-05-02 12:31:01 | 98 | +| 13 | 1003 | 9001 | 2020-01-02 10:01:01 | 2020-01-02 10:31:01 | 89 | +| 9 | 1001 | 9002 | 2020-02-02 12:01:01 | 2020-02-02 12:20:01 | 99 | +| 10 | 1002 | 9002 | 2021-02-02 12:01:01 | 2020-02-02 12:43:01 | 81 | +| 11 | 1001 | 9002 | 2020-01-02 19:01:01 | 2020-01-02 19:59:01 | 69 | +| 16 | 1002 | 9002 | 2020-02-02 12:01:01 | | | +| 17 | 1002 | 9002 | 2020-03-02 12:11:01 | | | +| 18 | 1001 | 9002 | 2021-05-05 18:01:01 | | | +| 4 | 1002 | 9003 | 2021-01-20 10:01:01 | 2021-01-20 10:10:01 | 81 | +| 6 | 1001 | 9003 | 2021-04-02 19:01:01 | 2021-04-02 19:40:01 | 89 | +| 15 | 1002 | 9003 | 2021-01-01 18:01:01 | 2021-01-01 18:59:02 | 90 | +| 7 | 1004 | 9004 | 2020-05-02 12:01:01 | 2020-05-02 12:20:01 | 99 | +| 12 | 1001 | 9004 | 2021-09-02 12:11:01 | | | +| 14 | 1002 | 9004 | 2020-01-01 12:11:01 | 2020-01-01 12:31:01 | 83 | 请计算 2021 年上半年各类试卷的做完次数相比 2020 年上半年同期的增长率(百分比格式,保留 1 位小数),以及做完次数排名变化,按增长率和 21 年排名降序输出。 由示例数据结果输出如下: -| tag | exam_cnt_20 | exam_cnt_21 | growth_rate | exam_cnt_rank_20 | exam_cnt_rank_21 | rank_delta | -| ---- | ----------- | ----------- | ----------- | ---------------- | ---------------- | ---------- | -| SQL | 3 | 2 | -33.3% | 1 | 2 | 1 | +| tag | exam_cnt_20 | exam_cnt_21 | growth_rate | exam_cnt_rank_20 | exam_cnt_rank_21 | rank_delta | +| --- | ----------- | ----------- | ----------- | ---------------- | ---------------- | ---------- | +| SQL | 3 | 2 | -33.3% | 1 | 2 | 1 | 解释:2020 年上半年有 3 个 tag 有作答完成的记录,分别是 C++、SQL、PYTHON,它们被做完的次数分别是 3、3、2,做完次数排名为 1、1(并列)、3; @@ -590,29 +590,29 @@ ORDER BY 现有试卷信息表 `examination_info`(`exam_id` 试卷 ID, `tag` 试卷类别, `difficulty` 试卷难度, `duration` 考试时长, `release_time` 发布时间): -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | ------ | ---------- | -------- | ------------------- | -| 1 | 9001 | SQL | hard | 60 | 2020-01-01 10:00:00 | -| 2 | 9002 | C++ | hard | 80 | 2020-01-01 10:00:00 | -| 3 | 9003 | 算法 | hard | 80 | 2020-01-01 10:00:00 | -| 4 | 9004 | PYTHON | medium | 70 | 2020-01-01 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | ------ | ---------- | -------- | ------------------- | +| 1 | 9001 | SQL | hard | 60 | 2020-01-01 10:00:00 | +| 2 | 9002 | C++ | hard | 80 | 2020-01-01 10:00:00 | +| 3 | 9003 | 算法 | hard | 80 | 2020-01-01 10:00:00 | +| 4 | 9004 | PYTHON | medium | 70 | 2020-01-01 10:00:00 | 试卷作答记录表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 6 | 1003 | 9001 | 2020-01-02 12:01:01 | 2020-01-02 12:31:01 | 68 | -| 9 | 1001 | 9001 | 2020-01-02 10:01:01 | 2020-01-02 10:31:01 | 89 | -| 1 | 1001 | 9001 | 2020-01-01 09:01:01 | 2020-01-01 09:21:59 | 90 | -| 12 | 1002 | 9002 | 2021-05-05 18:01:01 | (NULL) | (NULL) | -| 3 | 1004 | 9002 | 2020-01-01 12:01:01 | 2020-01-01 12:11:01 | 60 | -| 2 | 1003 | 9002 | 2020-01-01 19:01:01 | 2020-01-01 19:30:01 | 75 | -| 7 | 1001 | 9002 | 2020-01-02 12:01:01 | 2020-01-02 12:43:01 | 81 | -| 10 | 1002 | 9002 | 2020-01-01 12:11:01 | 2020-01-01 12:31:01 | 83 | -| 4 | 1003 | 9002 | 2020-01-01 12:01:01 | 2020-01-01 12:41:01 | 90 | -| 5 | 1002 | 9002 | 2020-01-02 19:01:01 | 2020-01-02 19:32:00 | 90 | -| 11 | 1002 | 9004 | 2021-09-06 12:01:01 | (NULL) | (NULL) | -| 8 | 1001 | 9005 | 2020-01-02 12:11:01 | (NULL) | (NULL) | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 6 | 1003 | 9001 | 2020-01-02 12:01:01 | 2020-01-02 12:31:01 | 68 | +| 9 | 1001 | 9001 | 2020-01-02 10:01:01 | 2020-01-02 10:31:01 | 89 | +| 1 | 1001 | 9001 | 2020-01-01 09:01:01 | 2020-01-01 09:21:59 | 90 | +| 12 | 1002 | 9002 | 2021-05-05 18:01:01 | (NULL) | (NULL) | +| 3 | 1004 | 9002 | 2020-01-01 12:01:01 | 2020-01-01 12:11:01 | 60 | +| 2 | 1003 | 9002 | 2020-01-01 19:01:01 | 2020-01-01 19:30:01 | 75 | +| 7 | 1001 | 9002 | 2020-01-02 12:01:01 | 2020-01-02 12:43:01 | 81 | +| 10 | 1002 | 9002 | 2020-01-01 12:11:01 | 2020-01-01 12:31:01 | 83 | +| 4 | 1003 | 9002 | 2020-01-01 12:01:01 | 2020-01-01 12:41:01 | 90 | +| 5 | 1002 | 9002 | 2020-01-02 19:01:01 | 2020-01-02 19:32:00 | 90 | +| 11 | 1002 | 9004 | 2021-09-06 12:01:01 | (NULL) | (NULL) | +| 8 | 1001 | 9005 | 2020-01-02 12:11:01 | (NULL) | (NULL) | 在物理学及统计学数据计算时,有个概念叫 min-max 标准化,也被称为离差标准化,是对原始数据的线性变换,使结果值映射到[0 - 1]之间。 @@ -694,20 +694,20 @@ ORDER BY 现有试卷作答记录表 exam_record(uid 用户 ID, exam_id 试卷 ID, start_time 开始作答时间, submit_time 交卷时间, score 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2020-01-01 09:01:01 | 2020-01-01 09:21:59 | 90 | -| 2 | 1002 | 9001 | 2020-01-20 10:01:01 | 2020-01-20 10:10:01 | 89 | -| 3 | 1002 | 9001 | 2020-02-01 12:11:01 | 2020-02-01 12:31:01 | 83 | -| 4 | 1003 | 9001 | 2020-03-01 19:01:01 | 2020-03-01 19:30:01 | 75 | -| 5 | 1004 | 9001 | 2020-03-01 12:01:01 | 2020-03-01 12:11:01 | 60 | -| 6 | 1003 | 9001 | 2020-03-01 12:01:01 | 2020-03-01 12:41:01 | 90 | -| 7 | 1002 | 9001 | 2020-05-02 19:01:01 | 2020-05-02 19:32:00 | 90 | -| 8 | 1001 | 9002 | 2020-01-02 19:01:01 | 2020-01-02 19:59:01 | 69 | -| 9 | 1004 | 9002 | 2020-02-02 12:01:01 | 2020-02-02 12:20:01 | 99 | -| 10 | 1003 | 9002 | 2020-02-02 12:01:01 | 2020-02-02 12:31:01 | 68 | -| 11 | 1001 | 9002 | 2020-02-02 12:01:01 | 2020-02-02 12:43:01 | 81 | -| 12 | 1001 | 9002 | 2020-03-02 12:11:01 | (NULL) | (NULL) | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2020-01-01 09:01:01 | 2020-01-01 09:21:59 | 90 | +| 2 | 1002 | 9001 | 2020-01-20 10:01:01 | 2020-01-20 10:10:01 | 89 | +| 3 | 1002 | 9001 | 2020-02-01 12:11:01 | 2020-02-01 12:31:01 | 83 | +| 4 | 1003 | 9001 | 2020-03-01 19:01:01 | 2020-03-01 19:30:01 | 75 | +| 5 | 1004 | 9001 | 2020-03-01 12:01:01 | 2020-03-01 12:11:01 | 60 | +| 6 | 1003 | 9001 | 2020-03-01 12:01:01 | 2020-03-01 12:41:01 | 90 | +| 7 | 1002 | 9001 | 2020-05-02 19:01:01 | 2020-05-02 19:32:00 | 90 | +| 8 | 1001 | 9002 | 2020-01-02 19:01:01 | 2020-01-02 19:59:01 | 69 | +| 9 | 1004 | 9002 | 2020-02-02 12:01:01 | 2020-02-02 12:20:01 | 99 | +| 10 | 1003 | 9002 | 2020-02-02 12:01:01 | 2020-02-02 12:31:01 | 68 | +| 11 | 1001 | 9002 | 2020-02-02 12:01:01 | 2020-02-02 12:43:01 | 81 | +| 12 | 1001 | 9002 | 2020-03-02 12:11:01 | (NULL) | (NULL) | 请输出每份试卷每月作答数和截止当月的作答总数。 由示例数据结果输出如下: @@ -747,31 +747,31 @@ GROUP BY exam_id, **描述**:现有试卷作答记录表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2020-01-01 09:01:01 | 2020-01-01 09:21:59 | 90 | -| 2 | 1002 | 9001 | 2020-01-20 10:01:01 | 2020-01-20 10:10:01 | 89 | -| 3 | 1002 | 9001 | 2020-02-01 12:11:01 | 2020-02-01 12:31:01 | 83 | -| 4 | 1003 | 9001 | 2020-03-01 19:01:01 | 2020-03-01 19:30:01 | 75 | -| 5 | 1004 | 9001 | 2020-03-01 12:01:01 | 2020-03-01 12:11:01 | 60 | -| 6 | 1003 | 9001 | 2020-03-01 12:01:01 | 2020-03-01 12:41:01 | 90 | -| 7 | 1002 | 9001 | 2020-05-02 19:01:01 | 2020-05-02 19:32:00 | 90 | -| 8 | 1001 | 9002 | 2020-01-02 19:01:01 | 2020-01-02 19:59:01 | 69 | -| 9 | 1004 | 9002 | 2020-02-02 12:01:01 | 2020-02-02 12:20:01 | 99 | -| 10 | 1003 | 9002 | 2020-02-02 12:01:01 | 2020-02-02 12:31:01 | 68 | -| 11 | 1001 | 9002 | 2020-01-02 19:01:01 | 2020-02-02 12:43:01 | 81 | -| 12 | 1001 | 9002 | 2020-03-02 12:11:01 | (NULL) | (NULL) | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2020-01-01 09:01:01 | 2020-01-01 09:21:59 | 90 | +| 2 | 1002 | 9001 | 2020-01-20 10:01:01 | 2020-01-20 10:10:01 | 89 | +| 3 | 1002 | 9001 | 2020-02-01 12:11:01 | 2020-02-01 12:31:01 | 83 | +| 4 | 1003 | 9001 | 2020-03-01 19:01:01 | 2020-03-01 19:30:01 | 75 | +| 5 | 1004 | 9001 | 2020-03-01 12:01:01 | 2020-03-01 12:11:01 | 60 | +| 6 | 1003 | 9001 | 2020-03-01 12:01:01 | 2020-03-01 12:41:01 | 90 | +| 7 | 1002 | 9001 | 2020-05-02 19:01:01 | 2020-05-02 19:32:00 | 90 | +| 8 | 1001 | 9002 | 2020-01-02 19:01:01 | 2020-01-02 19:59:01 | 69 | +| 9 | 1004 | 9002 | 2020-02-02 12:01:01 | 2020-02-02 12:20:01 | 99 | +| 10 | 1003 | 9002 | 2020-02-02 12:01:01 | 2020-02-02 12:31:01 | 68 | +| 11 | 1001 | 9002 | 2020-01-02 19:01:01 | 2020-02-02 12:43:01 | 81 | +| 12 | 1001 | 9002 | 2020-03-02 12:11:01 | (NULL) | (NULL) | 请输出自从有用户作答记录以来,每月的试卷作答记录中月活用户数、新增用户数、截止当月的单月最大新增用户数、截止当月的累积用户数。结果按月份升序输出。 由示例数据结果输出如下: -| start_month | mau | month_add_uv | max_month_add_uv | cum_sum_uv | -| ----------- | ---- | ------------ | ---------------- | ---------- | -| 202001 | 2 | 2 | 2 | 2 | -| 202002 | 4 | 2 | 2 | 4 | -| 202003 | 3 | 0 | 2 | 4 | -| 202005 | 1 | 0 | 2 | 4 | +| start_month | mau | month_add_uv | max_month_add_uv | cum_sum_uv | +| ----------- | --- | ------------ | ---------------- | ---------- | +| 202001 | 2 | 2 | 2 | 2 | +| 202002 | 4 | 2 | 2 | 4 | +| 202003 | 3 | 0 | 2 | 4 | +| 202005 | 1 | 0 | 2 | 4 | | month | 1001 | 1002 | 1003 | 1004 | | ------ | ---- | ---- | ---- | ---- | @@ -829,5 +829,4 @@ ORDER BY start_month ``` - - \ No newline at end of file + diff --git a/docs/database/sql/sql-questions-05.md b/docs/database/sql/sql-questions-05.md index 56366f74..c20af2ca 100644 --- a/docs/database/sql/sql-questions-05.md +++ b/docs/database/sql/sql-questions-05.md @@ -18,11 +18,11 @@ tag: 现有试卷作答记录表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分),数据如下: -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:01 | 80 | -| 2 | 1001 | 9001 | 2021-05-02 10:01:01 | 2021-05-02 10:30:01 | 81 | -| 3 | 1001 | 9001 | 2021-09-02 12:01:01 | (NULL) | (NULL) | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:01 | 80 | +| 2 | 1001 | 9001 | 2021-05-02 10:01:01 | 2021-05-02 10:30:01 | 81 | +| 3 | 1001 | 9001 | 2021-09-02 12:01:01 | (NULL) | (NULL) | 请统计有未完成状态的试卷的未完成数 incomplete_cnt 和未完成率 incomplete_rate。由示例数据结果输出如下: @@ -68,30 +68,30 @@ HAVING incomplete_cnt <> 0 现有用户信息表 `user_info`(`uid` 用户 ID,`nick_name` 昵称, `achievement` 成就值, `level` 等级, `job` 职业方向, `register_time` 注册时间),数据如下: -| id | uid | nick_name | achievement | level | job | register_time | -| ---- | ---- | --------- | ----------- | ----- | ---- | ------------------- | -| 1 | 1001 | 牛客 1 号 | 10 | 0 | 算法 | 2020-01-01 10:00:00 | -| 2 | 1002 | 牛客 2 号 | 2100 | 6 | 算法 | 2020-01-01 10:00:00 | +| id | uid | nick_name | achievement | level | job | register_time | +| --- | ---- | --------- | ----------- | ----- | ---- | ------------------- | +| 1 | 1001 | 牛客 1 号 | 10 | 0 | 算法 | 2020-01-01 10:00:00 | +| 2 | 1002 | 牛客 2 号 | 2100 | 6 | 算法 | 2020-01-01 10:00:00 | 试卷信息表 `examination_info`(`exam_id` 试卷 ID, `tag` 试卷类别, `difficulty` 试卷难度, `duration` 考试时长, `release_time` 发布时间),数据如下: -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | ---- | ---------- | -------- | ------------------- | -| 1 | 9001 | SQL | hard | 60 | 2020-01-01 10:00:00 | -| 2 | 9002 | SQL | easy | 60 | 2020-01-01 10:00:00 | -| 3 | 9004 | 算法 | medium | 80 | 2020-01-01 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | ---- | ---------- | -------- | ------------------- | +| 1 | 9001 | SQL | hard | 60 | 2020-01-01 10:00:00 | +| 2 | 9002 | SQL | easy | 60 | 2020-01-01 10:00:00 | +| 3 | 9004 | 算法 | medium | 80 | 2020-01-01 10:00:00 | 试卷作答记录表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分),数据如下: -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:59 | 80 | -| 2 | 1001 | 9001 | 2021-05-02 10:01:01 | (NULL) | (NULL) | -| 3 | 1001 | 9002 | 2021-02-02 19:01:01 | 2021-02-02 19:30:01 | 87 | -| 4 | 1001 | 9001 | 2021-06-02 19:01:01 | 2021-06-02 19:32:00 | 20 | -| 5 | 1001 | 9002 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 89 | -| 6 | 1001 | 9002 | 2021-09-01 12:01:01 | (NULL) | (NULL) | -| 7 | 1002 | 9002 | 2021-05-05 18:01:01 | 2021-05-05 18:59:02 | 90 | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:59 | 80 | +| 2 | 1001 | 9001 | 2021-05-02 10:01:01 | (NULL) | (NULL) | +| 3 | 1001 | 9002 | 2021-02-02 19:01:01 | 2021-02-02 19:30:01 | 87 | +| 4 | 1001 | 9001 | 2021-06-02 19:01:01 | 2021-06-02 19:32:00 | 20 | +| 5 | 1001 | 9002 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 89 | +| 6 | 1001 | 9002 | 2021-09-01 12:01:01 | (NULL) | (NULL) | +| 7 | 1002 | 9002 | 2021-05-05 18:01:01 | 2021-05-05 18:59:02 | 90 | 请输出每个 0 级用户所有的高难度试卷考试平均用时和平均得分,未完成的默认试卷最大考试时长和 0 分处理。由示例数据结果输出如下: @@ -129,46 +129,46 @@ ORDER BY UID 现有用户信息表 `user_info`(`uid` 用户 ID,`nick_name` 昵称, `achievement` 成就值, `level` 等级, `job` 职业方向, `register_time` 注册时间): -| id | uid | nick_name | achievement | level | job | register_time | -| ---- | ---- | ----------- | ----------- | ----- | ---- | ------------------- | -| 1 | 1001 | 牛客 1 号 | 1000 | 2 | 算法 | 2020-01-01 10:00:00 | -| 2 | 1002 | 牛客 2 号 | 1200 | 3 | 算法 | 2020-01-01 10:00:00 | -| 3 | 1003 | 进击的 3 号 | 2200 | 5 | 算法 | 2020-01-01 10:00:00 | -| 4 | 1004 | 牛客 4 号 | 2500 | 6 | 算法 | 2020-01-01 10:00:00 | -| 5 | 1005 | 牛客 5 号 | 3000 | 7 | C++ | 2020-01-01 10:00:00 | +| id | uid | nick_name | achievement | level | job | register_time | +| --- | ---- | ----------- | ----------- | ----- | ---- | ------------------- | +| 1 | 1001 | 牛客 1 号 | 1000 | 2 | 算法 | 2020-01-01 10:00:00 | +| 2 | 1002 | 牛客 2 号 | 1200 | 3 | 算法 | 2020-01-01 10:00:00 | +| 3 | 1003 | 进击的 3 号 | 2200 | 5 | 算法 | 2020-01-01 10:00:00 | +| 4 | 1004 | 牛客 4 号 | 2500 | 6 | 算法 | 2020-01-01 10:00:00 | +| 5 | 1005 | 牛客 5 号 | 3000 | 7 | C++ | 2020-01-01 10:00:00 | 试卷作答记录表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:59 | 80 | -| 3 | 1001 | 9002 | 2021-02-02 19:01:01 | 2021-02-02 19:30:01 | 87 | -| 2 | 1001 | 9001 | 2021-05-02 10:01:01 | (NULL) | (NULL) | -| 4 | 1001 | 9001 | 2021-06-02 19:01:01 | 2021-06-02 19:32:00 | 20 | -| 6 | 1001 | 9002 | 2021-09-01 12:01:01 | (NULL) | (NULL) | -| 5 | 1001 | 9002 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 89 | -| 11 | 1002 | 9001 | 2020-01-01 12:01:01 | 2020-01-01 12:31:01 | 81 | -| 12 | 1002 | 9002 | 2020-02-01 12:01:01 | 2020-02-01 12:31:01 | 82 | -| 13 | 1002 | 9002 | 2020-02-02 12:11:01 | 2020-02-02 12:31:01 | 83 | -| 7 | 1002 | 9002 | 2021-05-05 18:01:01 | 2021-05-05 18:59:02 | 90 | -| 16 | 1002 | 9001 | 2021-09-06 12:01:01 | 2021-09-06 12:21:01 | 80 | -| 17 | 1002 | 9001 | 2021-09-06 12:01:01 | (NULL) | (NULL) | -| 18 | 1002 | 9001 | 2021-09-07 12:01:01 | (NULL) | (NULL) | -| 8 | 1003 | 9003 | 2021-02-06 12:01:01 | (NULL) | (NULL) | -| 9 | 1003 | 9001 | 2021-09-07 10:01:01 | 2021-09-07 10:31:01 | 89 | -| 10 | 1004 | 9002 | 2021-08-06 12:01:01 | (NULL) | (NULL) | -| 14 | 1005 | 9001 | 2021-02-01 11:01:01 | 2021-02-01 11:31:01 | 84 | -| 15 | 1006 | 9001 | 2021-02-01 11:01:01 | 2021-02-01 11:31:01 | 84 | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:59 | 80 | +| 3 | 1001 | 9002 | 2021-02-02 19:01:01 | 2021-02-02 19:30:01 | 87 | +| 2 | 1001 | 9001 | 2021-05-02 10:01:01 | (NULL) | (NULL) | +| 4 | 1001 | 9001 | 2021-06-02 19:01:01 | 2021-06-02 19:32:00 | 20 | +| 6 | 1001 | 9002 | 2021-09-01 12:01:01 | (NULL) | (NULL) | +| 5 | 1001 | 9002 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 89 | +| 11 | 1002 | 9001 | 2020-01-01 12:01:01 | 2020-01-01 12:31:01 | 81 | +| 12 | 1002 | 9002 | 2020-02-01 12:01:01 | 2020-02-01 12:31:01 | 82 | +| 13 | 1002 | 9002 | 2020-02-02 12:11:01 | 2020-02-02 12:31:01 | 83 | +| 7 | 1002 | 9002 | 2021-05-05 18:01:01 | 2021-05-05 18:59:02 | 90 | +| 16 | 1002 | 9001 | 2021-09-06 12:01:01 | 2021-09-06 12:21:01 | 80 | +| 17 | 1002 | 9001 | 2021-09-06 12:01:01 | (NULL) | (NULL) | +| 18 | 1002 | 9001 | 2021-09-07 12:01:01 | (NULL) | (NULL) | +| 8 | 1003 | 9003 | 2021-02-06 12:01:01 | (NULL) | (NULL) | +| 9 | 1003 | 9001 | 2021-09-07 10:01:01 | 2021-09-07 10:31:01 | 89 | +| 10 | 1004 | 9002 | 2021-08-06 12:01:01 | (NULL) | (NULL) | +| 14 | 1005 | 9001 | 2021-02-01 11:01:01 | 2021-02-01 11:31:01 | 84 | +| 15 | 1006 | 9001 | 2021-02-01 11:01:01 | 2021-02-01 11:31:01 | 84 | 题目练习记录表 `practice_record`(`uid` 用户 ID, `question_id` 题目 ID, `submit_time` 提交时间, `score` 得分): -| id | uid | question_id | submit_time | score | -| ---- | ---- | ----------- | ------------------- | ----- | -| 1 | 1001 | 8001 | 2021-08-02 11:41:01 | 60 | -| 2 | 1002 | 8001 | 2021-09-02 19:30:01 | 50 | -| 3 | 1002 | 8001 | 2021-09-02 19:20:01 | 70 | -| 4 | 1002 | 8002 | 2021-09-02 19:38:01 | 70 | -| 5 | 1003 | 8002 | 2021-09-01 19:38:01 | 80 | +| id | uid | question_id | submit_time | score | +| --- | ---- | ----------- | ------------------- | ----- | +| 1 | 1001 | 8001 | 2021-08-02 11:41:01 | 60 | +| 2 | 1002 | 8001 | 2021-09-02 19:30:01 | 50 | +| 3 | 1002 | 8001 | 2021-09-02 19:20:01 | 70 | +| 4 | 1002 | 8002 | 2021-09-02 19:38:01 | 70 | +| 5 | 1003 | 8002 | 2021-09-01 19:38:01 | 80 | 请找到昵称以『牛客』开头『号』结尾、成就值在 1200~2500 之间,且最近一次活跃(答题或作答试卷)在 2021 年 9 月的用户信息。 @@ -217,45 +217,45 @@ GROUP BY u_info.uid 现有用户信息表 `user_info`(`uid` 用户 ID,`nick_name` 昵称, `achievement` 成就值, `level` 等级, `job` 职业方向, `register_time` 注册时间): -| id | uid | nick_name | achievement | level | job | register_time | -| ---- | ---- | ----------- | ----------- | ----- | ---- | ------------------- | -| 1 | 1001 | 牛客 1 号 | 1900 | 2 | 算法 | 2020-01-01 10:00:00 | -| 2 | 1002 | 牛客 2 号 | 1200 | 3 | 算法 | 2020-01-01 10:00:00 | -| 3 | 1003 | 牛客 3 号 ♂ | 2200 | 5 | 算法 | 2020-01-01 10:00:00 | -| 4 | 1004 | 牛客 4 号 | 2500 | 6 | 算法 | 2020-01-01 10:00:00 | -| 5 | 1005 | 牛客 555 号 | 2000 | 7 | C++ | 2020-01-01 10:00:00 | -| 6 | 1006 | 666666 | 3000 | 6 | C++ | 2020-01-01 10:00:00 | +| id | uid | nick_name | achievement | level | job | register_time | +| --- | ---- | ------------ | ----------- | ----- | ---- | ------------------- | +| 1 | 1001 | 牛客 1 号 | 1900 | 2 | 算法 | 2020-01-01 10:00:00 | +| 2 | 1002 | 牛客 2 号 | 1200 | 3 | 算法 | 2020-01-01 10:00:00 | +| 3 | 1003 | 牛客 3 号 ♂ | 2200 | 5 | 算法 | 2020-01-01 10:00:00 | +| 4 | 1004 | 牛客 4 号 | 2500 | 6 | 算法 | 2020-01-01 10:00:00 | +| 5 | 1005 | 牛客 555 号 | 2000 | 7 | C++ | 2020-01-01 10:00:00 | +| 6 | 1006 | 666666 | 3000 | 6 | C++ | 2020-01-01 10:00:00 | 试卷信息表 `examination_info`(`exam_id` 试卷 ID, `tag` 试卷类别, `difficulty` 试卷难度, `duration` 考试时长, `release_time` 发布时间): -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | ---- | ---------- | -------- | ------------------- | -| 1 | 9001 | C++ | hard | 60 | 2020-01-01 10:00:00 | -| 2 | 9002 | c# | hard | 80 | 2020-01-01 10:00:00 | -| 3 | 9003 | SQL | medium | 70 | 2020-01-01 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | --- | ---------- | -------- | ------------------- | +| 1 | 9001 | C++ | hard | 60 | 2020-01-01 10:00:00 | +| 2 | 9002 | c# | hard | 80 | 2020-01-01 10:00:00 | +| 3 | 9003 | SQL | medium | 70 | 2020-01-01 10:00:00 | 试卷作答记录表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:59 | 80 | -| 2 | 1001 | 9001 | 2021-05-02 10:01:01 | (NULL) | (NULL) | -| 4 | 1001 | 9001 | 2021-06-02 19:01:01 | 2021-06-02 19:32:00 | 20 | -| 3 | 1001 | 9002 | 2021-02-02 19:01:01 | 2021-02-02 19:30:01 | 87 | -| 5 | 1001 | 9002 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 89 | -| 6 | 1001 | 9002 | 2021-09-01 12:01:01 | (NULL) | (NULL) | -| 11 | 1002 | 9001 | 2020-01-01 12:01:01 | 2020-01-01 12:31:01 | 81 | -| 16 | 1002 | 9001 | 2021-09-06 12:01:01 | 2021-09-06 12:21:01 | 80 | -| 17 | 1002 | 9001 | 2021-09-06 12:01:01 | (NULL) | (NULL) | -| 18 | 1002 | 9001 | 2021-09-07 12:01:01 | (NULL) | (NULL) | -| 7 | 1002 | 9002 | 2021-05-05 18:01:01 | 2021-05-05 18:59:02 | 90 | -| 12 | 1002 | 9002 | 2020-02-01 12:01:01 | 2020-02-01 12:31:01 | 82 | -| 13 | 1002 | 9002 | 2020-02-02 12:11:01 | 2020-02-02 12:31:01 | 83 | -| 9 | 1003 | 9001 | 2021-09-07 10:01:01 | 2021-09-07 10:31:01 | 89 | -| 8 | 1003 | 9003 | 2021-02-06 12:01:01 | (NULL) | (NULL) | -| 10 | 1004 | 9002 | 2021-08-06 12:01:01 | (NULL) | (NULL) | -| 14 | 1005 | 9001 | 2021-02-01 11:01:01 | 2021-02-01 11:31:01 | 84 | -| 15 | 1006 | 9001 | 2021-02-01 11:01:01 | 2021-09-01 11:31:01 | 84 | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:59 | 80 | +| 2 | 1001 | 9001 | 2021-05-02 10:01:01 | (NULL) | (NULL) | +| 4 | 1001 | 9001 | 2021-06-02 19:01:01 | 2021-06-02 19:32:00 | 20 | +| 3 | 1001 | 9002 | 2021-02-02 19:01:01 | 2021-02-02 19:30:01 | 87 | +| 5 | 1001 | 9002 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 89 | +| 6 | 1001 | 9002 | 2021-09-01 12:01:01 | (NULL) | (NULL) | +| 11 | 1002 | 9001 | 2020-01-01 12:01:01 | 2020-01-01 12:31:01 | 81 | +| 16 | 1002 | 9001 | 2021-09-06 12:01:01 | 2021-09-06 12:21:01 | 80 | +| 17 | 1002 | 9001 | 2021-09-06 12:01:01 | (NULL) | (NULL) | +| 18 | 1002 | 9001 | 2021-09-07 12:01:01 | (NULL) | (NULL) | +| 7 | 1002 | 9002 | 2021-05-05 18:01:01 | 2021-05-05 18:59:02 | 90 | +| 12 | 1002 | 9002 | 2020-02-01 12:01:01 | 2020-02-01 12:31:01 | 82 | +| 13 | 1002 | 9002 | 2020-02-02 12:11:01 | 2020-02-02 12:31:01 | 83 | +| 9 | 1003 | 9001 | 2021-09-07 10:01:01 | 2021-09-07 10:31:01 | 89 | +| 8 | 1003 | 9003 | 2021-02-06 12:01:01 | (NULL) | (NULL) | +| 10 | 1004 | 9002 | 2021-08-06 12:01:01 | (NULL) | (NULL) | +| 14 | 1005 | 9001 | 2021-02-01 11:01:01 | 2021-02-01 11:31:01 | 84 | +| 15 | 1006 | 9001 | 2021-02-01 11:01:01 | 2021-09-01 11:31:01 | 84 | 找到昵称以"牛客"+纯数字+"号"或者纯数字组成的用户对于字母 c 开头的试卷类别(如 C,C++,c#等)的已完成的试卷 ID 和平均得分,按用户 ID、平均分升序排序。由示例数据结果输出如下: @@ -311,32 +311,32 @@ ORDER BY UID,avg_score; 现有用户信息表 `user_info`(`uid` 用户 ID,`nick_name` 昵称, `achievement` 成就值, `level` 等级, `job` 职业方向, `register_time` 注册时间): -| id | uid | nick_name | achievement | level | job | register_time | -| ---- | ---- | ----------- | ----------- | ----- | ---- | ------------------- | -| 1 | 1001 | 牛客 1 号 | 19 | 0 | 算法 | 2020-01-01 10:00:00 | -| 2 | 1002 | 牛客 2 号 | 1200 | 3 | 算法 | 2020-01-01 10:00:00 | -| 3 | 1003 | 进击的 3 号 | 22 | 0 | 算法 | 2020-01-01 10:00:00 | -| 4 | 1004 | 牛客 4 号 | 25 | 0 | 算法 | 2020-01-01 10:00:00 | -| 5 | 1005 | 牛客 555 号 | 2000 | 7 | C++ | 2020-01-01 10:00:00 | -| 6 | 1006 | 666666 | 3000 | 6 | C++ | 2020-01-01 10:00:00 | +| id | uid | nick_name | achievement | level | job | register_time | +| --- | ---- | ----------- | ----------- | ----- | ---- | ------------------- | +| 1 | 1001 | 牛客 1 号 | 19 | 0 | 算法 | 2020-01-01 10:00:00 | +| 2 | 1002 | 牛客 2 号 | 1200 | 3 | 算法 | 2020-01-01 10:00:00 | +| 3 | 1003 | 进击的 3 号 | 22 | 0 | 算法 | 2020-01-01 10:00:00 | +| 4 | 1004 | 牛客 4 号 | 25 | 0 | 算法 | 2020-01-01 10:00:00 | +| 5 | 1005 | 牛客 555 号 | 2000 | 7 | C++ | 2020-01-01 10:00:00 | +| 6 | 1006 | 666666 | 3000 | 6 | C++ | 2020-01-01 10:00:00 | 试卷作答记录表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:59 | 80 | -| 2 | 1001 | 9001 | 2021-05-02 10:01:01 | (NULL) | (NULL) | -| 3 | 1001 | 9002 | 2021-02-02 19:01:01 | 2021-02-02 19:30:01 | 87 | -| 4 | 1001 | 9002 | 2021-09-01 12:01:01 | (NULL) | (NULL) | -| 5 | 1001 | 9003 | 2021-09-02 12:01:01 | (NULL) | (NULL) | -| 6 | 1001 | 9004 | 2021-09-03 12:01:01 | (NULL) | (NULL) | -| 7 | 1002 | 9001 | 2020-01-01 12:01:01 | 2020-01-01 12:31:01 | 99 | -| 8 | 1002 | 9003 | 2020-02-01 12:01:01 | 2020-02-01 12:31:01 | 82 | -| 9 | 1002 | 9003 | 2020-02-02 12:11:01 | (NULL) | (NULL) | -| 10 | 1002 | 9002 | 2021-05-05 18:01:01 | (NULL) | (NULL) | -| 11 | 1002 | 9001 | 2021-09-06 12:01:01 | (NULL) | (NULL) | -| 12 | 1003 | 9003 | 2021-02-06 12:01:01 | (NULL) | (NULL) | -| 13 | 1003 | 9001 | 2021-09-07 10:01:01 | 2021-09-07 10:31:01 | 89 | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:59 | 80 | +| 2 | 1001 | 9001 | 2021-05-02 10:01:01 | (NULL) | (NULL) | +| 3 | 1001 | 9002 | 2021-02-02 19:01:01 | 2021-02-02 19:30:01 | 87 | +| 4 | 1001 | 9002 | 2021-09-01 12:01:01 | (NULL) | (NULL) | +| 5 | 1001 | 9003 | 2021-09-02 12:01:01 | (NULL) | (NULL) | +| 6 | 1001 | 9004 | 2021-09-03 12:01:01 | (NULL) | (NULL) | +| 7 | 1002 | 9001 | 2020-01-01 12:01:01 | 2020-01-01 12:31:01 | 99 | +| 8 | 1002 | 9003 | 2020-02-01 12:01:01 | 2020-02-01 12:31:01 | 82 | +| 9 | 1002 | 9003 | 2020-02-02 12:11:01 | (NULL) | (NULL) | +| 10 | 1002 | 9002 | 2021-05-05 18:01:01 | (NULL) | (NULL) | +| 11 | 1002 | 9001 | 2021-09-06 12:01:01 | (NULL) | (NULL) | +| 12 | 1003 | 9003 | 2021-02-06 12:01:01 | (NULL) | (NULL) | +| 13 | 1003 | 9001 | 2021-09-07 10:01:01 | 2021-09-07 10:31:01 | 89 | 请你筛选表中的数据,当有任意一个 0 级用户未完成试卷数大于 2 时,输出每个 0 级用户的试卷未完成数和未完成率(保留 3 位小数);若不存在这样的用户,则输出所有有作答记录的用户的这两个指标。结果按未完成率升序排序。 @@ -537,30 +537,30 @@ CASE 现有用户信息表 `user_info`(`uid` 用户 ID,`nick_name` 昵称, `achievement` 成就值, `level` 等级, `job` 职业方向, `register_time` 注册时间): -| id | uid | nick_name | achievement | level | job | register_time | -| ---- | ---- | ----------- | ----------- | ----- | ---- | ------------------- | -| 1 | 1001 | 牛客 1 号 | 19 | 0 | 算法 | 2020-01-01 10:00:00 | -| 2 | 1002 | 牛客 2 号 | 1200 | 3 | 算法 | 2020-01-01 10:00:00 | -| 3 | 1003 | 牛客 3 号 ♂ | 22 | 0 | 算法 | 2020-01-01 10:00:00 | -| 4 | 1004 | 牛客 4 号 | 25 | 0 | 算法 | 2020-01-01 10:00:00 | -| 5 | 1005 | 牛客 555 号 | 2000 | 7 | C++ | 2020-01-01 10:00:00 | -| 6 | 1006 | 666666 | 3000 | 6 | C++ | 2020-01-01 10:00:00 | +| id | uid | nick_name | achievement | level | job | register_time | +| --- | ---- | ------------ | ----------- | ----- | ---- | ------------------- | +| 1 | 1001 | 牛客 1 号 | 19 | 0 | 算法 | 2020-01-01 10:00:00 | +| 2 | 1002 | 牛客 2 号 | 1200 | 3 | 算法 | 2020-01-01 10:00:00 | +| 3 | 1003 | 牛客 3 号 ♂ | 22 | 0 | 算法 | 2020-01-01 10:00:00 | +| 4 | 1004 | 牛客 4 号 | 25 | 0 | 算法 | 2020-01-01 10:00:00 | +| 5 | 1005 | 牛客 555 号 | 2000 | 7 | C++ | 2020-01-01 10:00:00 | +| 6 | 1006 | 666666 | 3000 | 6 | C++ | 2020-01-01 10:00:00 | 试卷作答记录表 exam_record(uid 用户 ID, exam_id 试卷 ID, start_time 开始作答时间, submit_time 交卷时间, score 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:59 | 80 | -| 2 | 1001 | 9001 | 2021-05-02 10:01:01 | (NULL) | (NULL) | -| 3 | 1001 | 9002 | 2021-02-02 19:01:01 | 2021-02-02 19:30:01 | 75 | -| 4 | 1001 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:11:01 | 60 | -| 5 | 1001 | 9003 | 2021-09-02 12:01:01 | 2021-09-02 12:41:01 | 90 | -| 6 | 1001 | 9001 | 2021-06-02 19:01:01 | 2021-06-02 19:32:00 | 20 | -| 7 | 1001 | 9002 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 89 | -| 8 | 1001 | 9004 | 2021-09-03 12:01:01 | (NULL) | (NULL) | -| 9 | 1002 | 9001 | 2020-01-01 12:01:01 | 2020-01-01 12:31:01 | 99 | -| 10 | 1002 | 9003 | 2020-02-01 12:01:01 | 2020-02-01 12:31:01 | 82 | -| 11 | 1002 | 9003 | 2020-02-02 12:11:01 | 2020-02-02 12:41:01 | 76 | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:59 | 80 | +| 2 | 1001 | 9001 | 2021-05-02 10:01:01 | (NULL) | (NULL) | +| 3 | 1001 | 9002 | 2021-02-02 19:01:01 | 2021-02-02 19:30:01 | 75 | +| 4 | 1001 | 9002 | 2021-09-01 12:01:01 | 2021-09-01 12:11:01 | 60 | +| 5 | 1001 | 9003 | 2021-09-02 12:01:01 | 2021-09-02 12:41:01 | 90 | +| 6 | 1001 | 9001 | 2021-06-02 19:01:01 | 2021-06-02 19:32:00 | 20 | +| 7 | 1001 | 9002 | 2021-09-05 19:01:01 | 2021-09-05 19:40:01 | 89 | +| 8 | 1001 | 9004 | 2021-09-03 12:01:01 | (NULL) | (NULL) | +| 9 | 1002 | 9001 | 2020-01-01 12:01:01 | 2020-01-01 12:31:01 | 99 | +| 10 | 1002 | 9003 | 2020-02-01 12:01:01 | 2020-02-01 12:31:01 | 82 | +| 11 | 1002 | 9003 | 2020-02-02 12:11:01 | 2020-02-02 12:41:01 | 76 | 为了得到用户试卷作答的定性表现,我们将试卷得分按分界点[90,75,60]分为优良中差四个得分等级(分界点划分到左区间),请统计不同用户等级的人在完成过的试卷中各得分等级占比(结果保留 3 位小数),未完成过试卷的用户无需输出,结果按用户等级降序、占比降序排序。 @@ -649,22 +649,22 @@ ORDER BY a.LEVEL DESC, 现有用户信息表 `user_info`(`uid` 用户 ID,`nick_name` 昵称, `achievement` 成就值, `level` 等级, `job` 职业方向, `register_time` 注册时间): -| id | uid | nick_name | achievement | level | job | register_time | -| ---- | ---- | ----------- | ----------- | ----- | ---- | ------------------- | -| 1 | 1001 | 牛客 1 号 | 19 | 0 | 算法 | 2020-01-01 10:00:00 | -| 2 | 1002 | 牛客 2 号 | 1200 | 3 | 算法 | 2020-02-01 10:00:00 | -| 3 | 1003 | 牛客 3 号 ♂ | 22 | 0 | 算法 | 2020-01-02 10:00:00 | -| 4 | 1004 | 牛客 4 号 | 25 | 0 | 算法 | 2020-01-02 11:00:00 | -| 5 | 1005 | 牛客 555 号 | 4000 | 7 | C++ | 2020-01-11 10:00:00 | -| 6 | 1006 | 666666 | 3000 | 6 | C++ | 2020-11-01 10:00:00 | +| id | uid | nick_name | achievement | level | job | register_time | +| --- | ---- | ------------ | ----------- | ----- | ---- | ------------------- | +| 1 | 1001 | 牛客 1 号 | 19 | 0 | 算法 | 2020-01-01 10:00:00 | +| 2 | 1002 | 牛客 2 号 | 1200 | 3 | 算法 | 2020-02-01 10:00:00 | +| 3 | 1003 | 牛客 3 号 ♂ | 22 | 0 | 算法 | 2020-01-02 10:00:00 | +| 4 | 1004 | 牛客 4 号 | 25 | 0 | 算法 | 2020-01-02 11:00:00 | +| 5 | 1005 | 牛客 555 号 | 4000 | 7 | C++ | 2020-01-11 10:00:00 | +| 6 | 1006 | 666666 | 3000 | 6 | C++ | 2020-11-01 10:00:00 | 请从中找到注册时间最早的 3 个人。由示例数据结果输出如下: -| uid | nick_name | register_time | -| ---- | ----------- | ------------------- | -| 1001 | 牛客 1 | 2020-01-01 10:00:00 | +| uid | nick_name | register_time | +| ---- | ------------ | ------------------- | +| 1001 | 牛客 1 | 2020-01-01 10:00:00 | | 1003 | 牛客 3 号 ♂ | 2020-01-02 10:00:00 | -| 1004 | 牛客 4 号 | 2020-01-02 11:00:00 | +| 1004 | 牛客 4 号 | 2020-01-02 11:00:00 | 解释:按注册时间排序后选取前三名,输出其用户 ID、昵称、注册时间。 @@ -681,45 +681,45 @@ SELECT uid, nick_name, register_time **描述**:现有用户信息表 `user_info`(`uid` 用户 ID,`nick_name` 昵称, `achievement` 成就值, `level` 等级, `job` 职业方向, `register_time` 注册时间): -| id | uid | nick_name | achievement | level | job | register_time | -| ---- | ---- | ----------- | ----------- | ----- | ---- | ------------------- | -| 1 | 1001 | 牛客 1 | 19 | 0 | 算法 | 2020-01-01 10:00:00 | -| 2 | 1002 | 牛客 2 号 | 1200 | 3 | 算法 | 2020-01-01 10:00:00 | -| 3 | 1003 | 牛客 3 号 ♂ | 22 | 0 | 算法 | 2020-01-01 10:00:00 | -| 4 | 1004 | 牛客 4 号 | 25 | 0 | 算法 | 2020-01-01 10:00:00 | -| 5 | 1005 | 牛客 555 号 | 4000 | 7 | 算法 | 2020-01-11 10:00:00 | -| 6 | 1006 | 牛客 6 号 | 25 | 0 | 算法 | 2020-01-02 11:00:00 | -| 7 | 1007 | 牛客 7 号 | 25 | 0 | 算法 | 2020-01-02 11:00:00 | -| 8 | 1008 | 牛客 8 号 | 25 | 0 | 算法 | 2020-01-02 11:00:00 | -| 9 | 1009 | 牛客 9 号 | 25 | 0 | 算法 | 2020-01-02 11:00:00 | -| 10 | 1010 | 牛客 10 号 | 25 | 0 | 算法 | 2020-01-02 11:00:00 | -| 11 | 1011 | 666666 | 3000 | 6 | C++ | 2020-01-02 10:00:00 | +| id | uid | nick_name | achievement | level | job | register_time | +| --- | ---- | ------------ | ----------- | ----- | ---- | ------------------- | +| 1 | 1001 | 牛客 1 | 19 | 0 | 算法 | 2020-01-01 10:00:00 | +| 2 | 1002 | 牛客 2 号 | 1200 | 3 | 算法 | 2020-01-01 10:00:00 | +| 3 | 1003 | 牛客 3 号 ♂ | 22 | 0 | 算法 | 2020-01-01 10:00:00 | +| 4 | 1004 | 牛客 4 号 | 25 | 0 | 算法 | 2020-01-01 10:00:00 | +| 5 | 1005 | 牛客 555 号 | 4000 | 7 | 算法 | 2020-01-11 10:00:00 | +| 6 | 1006 | 牛客 6 号 | 25 | 0 | 算法 | 2020-01-02 11:00:00 | +| 7 | 1007 | 牛客 7 号 | 25 | 0 | 算法 | 2020-01-02 11:00:00 | +| 8 | 1008 | 牛客 8 号 | 25 | 0 | 算法 | 2020-01-02 11:00:00 | +| 9 | 1009 | 牛客 9 号 | 25 | 0 | 算法 | 2020-01-02 11:00:00 | +| 10 | 1010 | 牛客 10 号 | 25 | 0 | 算法 | 2020-01-02 11:00:00 | +| 11 | 1011 | 666666 | 3000 | 6 | C++ | 2020-01-02 10:00:00 | 试卷信息表 examination_info(exam_id 试卷 ID, tag 试卷类别, difficulty 试卷难度, duration 考试时长, release_time 发布时间): -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | ---- | ---------- | -------- | ------------------- | -| 1 | 9001 | 算法 | hard | 60 | 2020-01-01 10:00:00 | -| 2 | 9002 | 算法 | hard | 80 | 2020-01-01 10:00:00 | -| 3 | 9003 | SQL | medium | 70 | 2020-01-01 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | ---- | ---------- | -------- | ------------------- | +| 1 | 9001 | 算法 | hard | 60 | 2020-01-01 10:00:00 | +| 2 | 9002 | 算法 | hard | 80 | 2020-01-01 10:00:00 | +| 3 | 9003 | SQL | medium | 70 | 2020-01-01 10:00:00 | 试卷作答记录表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ----- | -| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:59 | 80 | -| 2 | 1002 | 9003 | 2020-01-20 10:01:01 | 2020-01-20 10:10:01 | 81 | -| 3 | 1002 | 9002 | 2020-01-01 12:11:01 | 2020-01-01 12:31:01 | 83 | -| 4 | 1003 | 9002 | 2020-01-01 19:01:01 | 2020-01-01 19:30:01 | 75 | -| 5 | 1004 | 9002 | 2020-01-01 12:01:01 | 2020-01-01 12:11:01 | 60 | -| 6 | 1005 | 9002 | 2020-01-01 12:01:01 | 2020-01-01 12:41:01 | 90 | -| 7 | 1006 | 9001 | 2020-01-02 19:01:01 | 2020-01-02 19:32:00 | 20 | -| 8 | 1007 | 9002 | 2020-01-02 19:01:01 | 2020-01-02 19:40:01 | 89 | -| 9 | 1008 | 9003 | 2020-01-02 12:01:01 | 2020-01-02 12:20:01 | 99 | -| 10 | 1008 | 9001 | 2020-01-02 12:01:01 | 2020-01-02 12:31:01 | 98 | -| 11 | 1009 | 9002 | 2020-01-02 12:01:01 | 2020-01-02 12:31:01 | 82 | -| 12 | 1010 | 9002 | 2020-01-02 12:11:01 | 2020-01-02 12:41:01 | 76 | -| 13 | 1011 | 9001 | 2020-01-02 10:01:01 | 2020-01-02 10:31:01 | 89 | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ----- | +| 1 | 1001 | 9001 | 2020-01-02 09:01:01 | 2020-01-02 09:21:59 | 80 | +| 2 | 1002 | 9003 | 2020-01-20 10:01:01 | 2020-01-20 10:10:01 | 81 | +| 3 | 1002 | 9002 | 2020-01-01 12:11:01 | 2020-01-01 12:31:01 | 83 | +| 4 | 1003 | 9002 | 2020-01-01 19:01:01 | 2020-01-01 19:30:01 | 75 | +| 5 | 1004 | 9002 | 2020-01-01 12:01:01 | 2020-01-01 12:11:01 | 60 | +| 6 | 1005 | 9002 | 2020-01-01 12:01:01 | 2020-01-01 12:41:01 | 90 | +| 7 | 1006 | 9001 | 2020-01-02 19:01:01 | 2020-01-02 19:32:00 | 20 | +| 8 | 1007 | 9002 | 2020-01-02 19:01:01 | 2020-01-02 19:40:01 | 89 | +| 9 | 1008 | 9003 | 2020-01-02 12:01:01 | 2020-01-02 12:20:01 | 99 | +| 10 | 1008 | 9001 | 2020-01-02 12:01:01 | 2020-01-02 12:31:01 | 98 | +| 11 | 1009 | 9002 | 2020-01-02 12:01:01 | 2020-01-02 12:31:01 | 82 | +| 12 | 1010 | 9002 | 2020-01-02 12:11:01 | 2020-01-02 12:41:01 | 76 | +| 13 | 1011 | 9001 | 2020-01-02 10:01:01 | 2020-01-02 10:31:01 | 89 | ![](https://oss.javaguide.cn/github/javaguide/database/sql/D2B491866B85826119EE3474F10D3636.png) @@ -784,12 +784,12 @@ LIMIT 6,3 **描述**:现有试卷信息表 `examination_info`(`exam_id` 试卷 ID, `tag` 试卷类别, `difficulty` 试卷难度, `duration` 考试时长, `release_time` 发布时间): -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | -------------- | ---------- | -------- | ------------------- | -| 1 | 9001 | 算法 | hard | 60 | 2021-01-01 10:00:00 | -| 2 | 9002 | 算法 | hard | 80 | 2021-01-01 10:00:00 | -| 3 | 9003 | SQL | medium | 70 | 2021-01-01 10:00:00 | -| 4 | 9004 | 算法,medium,80 | | 0 | 2021-01-01 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | -------------- | ---------- | -------- | ------------------- | +| 1 | 9001 | 算法 | hard | 60 | 2021-01-01 10:00:00 | +| 2 | 9002 | 算法 | hard | 80 | 2021-01-01 10:00:00 | +| 3 | 9003 | SQL | medium | 70 | 2021-01-01 10:00:00 | +| 4 | 9004 | 算法,medium,80 | | 0 | 2021-01-01 10:00:00 | 录题同学有一次手误将部分记录的试题类别 tag、难度、时长同时录入到了 tag 字段,请帮忙找出这些录错了的记录,并拆分后按正确的列类型输出。 @@ -865,14 +865,14 @@ WHERE **描述**:现有用户信息表 `user_info`(`uid` 用户 ID,`nick_name` 昵称, `achievement` 成就值, `level` 等级, `job` 职业方向, `register_time` 注册时间): -| id | uid | nick_name | achievement | level | job | register_time | -| ---- | ---- | ---------------------- | ----------- | ----- | ---- | ------------------- | -| 1 | 1001 | 牛客 1 | 19 | 0 | 算法 | 2020-01-01 10:00:00 | -| 2 | 1002 | 牛客 2 号 | 1200 | 3 | 算法 | 2020-01-01 10:00:00 | -| 3 | 1003 | 牛客 3 号 ♂ | 22 | 0 | 算法 | 2020-01-01 10:00:00 | -| 4 | 1004 | 牛客 4 号 | 25 | 0 | 算法 | 2020-01-01 11:00:00 | -| 5 | 1005 | 牛客 5678901234 号 | 4000 | 7 | 算法 | 2020-01-11 10:00:00 | -| 6 | 1006 | 牛客 67890123456789 号 | 25 | 0 | 算法 | 2020-01-02 11:00:00 | +| id | uid | nick_name | achievement | level | job | register_time | +| --- | ---- | ---------------------- | ----------- | ----- | ---- | ------------------- | +| 1 | 1001 | 牛客 1 | 19 | 0 | 算法 | 2020-01-01 10:00:00 | +| 2 | 1002 | 牛客 2 号 | 1200 | 3 | 算法 | 2020-01-01 10:00:00 | +| 3 | 1003 | 牛客 3 号 ♂ | 22 | 0 | 算法 | 2020-01-01 10:00:00 | +| 4 | 1004 | 牛客 4 号 | 25 | 0 | 算法 | 2020-01-01 11:00:00 | +| 5 | 1005 | 牛客 5678901234 号 | 4000 | 7 | 算法 | 2020-01-11 10:00:00 | +| 6 | 1006 | 牛客 67890123456789 号 | 25 | 0 | 算法 | 2020-01-02 11:00:00 | 有的用户的昵称特别长,在一些展示场景会导致样式混乱,因此需要将特别长的昵称转换一下再输出,请输出字符数大于 10 的用户信息,对于字符数大于 13 的用户输出前 10 个字符然后加上三个点号:『...』。 @@ -929,36 +929,36 @@ GROUP BY 现有试卷信息表 `examination_info`(`exam_id` 试卷 ID, `tag` 试卷类别, `difficulty` 试卷难度, `duration` 考试时长, `release_time` 发布时间): -| id | exam_id | tag | difficulty | duration | release_time | -| ---- | ------- | ---- | ---------- | -------- | ------------------- | -| 1 | 9001 | 算法 | hard | 60 | 2021-01-01 10:00:00 | -| 2 | 9002 | C++ | hard | 80 | 2021-01-01 10:00:00 | -| 3 | 9003 | C++ | hard | 80 | 2021-01-01 10:00:00 | -| 4 | 9004 | sql | medium | 70 | 2021-01-01 10:00:00 | -| 5 | 9005 | C++ | hard | 80 | 2021-01-01 10:00:00 | -| 6 | 9006 | C++ | hard | 80 | 2021-01-01 10:00:00 | -| 7 | 9007 | C++ | hard | 80 | 2021-01-01 10:00:00 | -| 8 | 9008 | SQL | medium | 70 | 2021-01-01 10:00:00 | -| 9 | 9009 | SQL | medium | 70 | 2021-01-01 10:00:00 | -| 10 | 9010 | SQL | medium | 70 | 2021-01-01 10:00:00 | +| id | exam_id | tag | difficulty | duration | release_time | +| --- | ------- | ---- | ---------- | -------- | ------------------- | +| 1 | 9001 | 算法 | hard | 60 | 2021-01-01 10:00:00 | +| 2 | 9002 | C++ | hard | 80 | 2021-01-01 10:00:00 | +| 3 | 9003 | C++ | hard | 80 | 2021-01-01 10:00:00 | +| 4 | 9004 | sql | medium | 70 | 2021-01-01 10:00:00 | +| 5 | 9005 | C++ | hard | 80 | 2021-01-01 10:00:00 | +| 6 | 9006 | C++ | hard | 80 | 2021-01-01 10:00:00 | +| 7 | 9007 | C++ | hard | 80 | 2021-01-01 10:00:00 | +| 8 | 9008 | SQL | medium | 70 | 2021-01-01 10:00:00 | +| 9 | 9009 | SQL | medium | 70 | 2021-01-01 10:00:00 | +| 10 | 9010 | SQL | medium | 70 | 2021-01-01 10:00:00 | 试卷作答信息表 `exam_record`(`uid` 用户 ID, `exam_id` 试卷 ID, `start_time` 开始作答时间, `submit_time` 交卷时间, `score` 得分): -| id | uid | exam_id | start_time | submit_time | score | -| ---- | ---- | ------- | ------------------- | ------------------- | ------ | -| 1 | 1001 | 9001 | 2020-01-01 09:01:01 | 2020-01-01 09:21:59 | 80 | -| 2 | 1002 | 9003 | 2020-01-20 10:01:01 | 2020-01-20 10:10:01 | 81 | -| 3 | 1002 | 9002 | 2020-02-01 12:11:01 | 2020-02-01 12:31:01 | 83 | -| 4 | 1003 | 9002 | 2020-03-01 19:01:01 | 2020-03-01 19:30:01 | 75 | -| 5 | 1004 | 9002 | 2020-03-01 12:01:01 | 2020-03-01 12:11:01 | 60 | -| 6 | 1005 | 9002 | 2020-03-01 12:01:01 | 2020-03-01 12:41:01 | 90 | -| 7 | 1006 | 9001 | 2020-05-02 19:01:01 | 2020-05-02 19:32:00 | 20 | -| 8 | 1007 | 9003 | 2020-01-02 19:01:01 | 2020-01-02 19:40:01 | 89 | -| 9 | 1008 | 9004 | 2020-02-02 12:01:01 | 2020-02-02 12:20:01 | 99 | -| 10 | 1008 | 9001 | 2020-02-02 12:01:01 | 2020-02-02 12:31:01 | 98 | -| 11 | 1009 | 9002 | 2020-02-02 12:01:01 | 2020-01-02 12:43:01 | 81 | -| 12 | 1010 | 9001 | 2020-01-02 12:11:01 | (NULL) | (NULL) | -| 13 | 1010 | 9001 | 2020-02-02 12:01:01 | 2020-01-02 10:31:01 | 89 | +| id | uid | exam_id | start_time | submit_time | score | +| --- | ---- | ------- | ------------------- | ------------------- | ------ | +| 1 | 1001 | 9001 | 2020-01-01 09:01:01 | 2020-01-01 09:21:59 | 80 | +| 2 | 1002 | 9003 | 2020-01-20 10:01:01 | 2020-01-20 10:10:01 | 81 | +| 3 | 1002 | 9002 | 2020-02-01 12:11:01 | 2020-02-01 12:31:01 | 83 | +| 4 | 1003 | 9002 | 2020-03-01 19:01:01 | 2020-03-01 19:30:01 | 75 | +| 5 | 1004 | 9002 | 2020-03-01 12:01:01 | 2020-03-01 12:11:01 | 60 | +| 6 | 1005 | 9002 | 2020-03-01 12:01:01 | 2020-03-01 12:41:01 | 90 | +| 7 | 1006 | 9001 | 2020-05-02 19:01:01 | 2020-05-02 19:32:00 | 20 | +| 8 | 1007 | 9003 | 2020-01-02 19:01:01 | 2020-01-02 19:40:01 | 89 | +| 9 | 1008 | 9004 | 2020-02-02 12:01:01 | 2020-02-02 12:20:01 | 99 | +| 10 | 1008 | 9001 | 2020-02-02 12:01:01 | 2020-02-02 12:31:01 | 98 | +| 11 | 1009 | 9002 | 2020-02-02 12:01:01 | 2020-01-02 12:43:01 | 81 | +| 12 | 1010 | 9001 | 2020-01-02 12:11:01 | (NULL) | (NULL) | +| 13 | 1010 | 9001 | 2020-02-02 12:01:01 | 2020-01-02 10:31:01 | 89 | 试卷的类别 tag 可能出现大小写混乱的情况,请先筛选出试卷作答数小于 3 的类别 tag,统计将其转换为大写后对应的原本试卷作答数。 @@ -966,9 +966,9 @@ GROUP BY 由示例数据结果输出如下: -| tag | answer_cnt | -| ---- | ---------- | -| C++ | 6 | +| tag | answer_cnt | +| --- | ---------- | +| C++ | 6 | 解释:被作答过的试卷有 9001、9002、9003、9004,他们的 tag 和被作答次数如下: @@ -1010,4 +1010,4 @@ AND a.tag != b.tag WHERE a.answer_cnt < 3; ``` - \ No newline at end of file + diff --git a/docs/database/sql/sql-syntax-summary.md b/docs/database/sql/sql-syntax-summary.md index 2da62cff..467a6f14 100644 --- a/docs/database/sql/sql-syntax-summary.md +++ b/docs/database/sql/sql-syntax-summary.md @@ -556,7 +556,7 @@ SELECT column_name(s) FROM table2; | `LEFT()`、`RIGHT()` | 左边或者右边的字符 | | `LOWER()`、`UPPER()` | 转换为小写或者大写 | | `LTRIM()`、`RTRIM()` | 去除左边或者右边的空格 | -| `LENGTH()` | 长度,以字节为单位 | +| `LENGTH()` | 长度,以字节为单位 | | `SOUNDEX()` | 转换为语音值 | 其中, **`SOUNDEX()`** 可以将一个字符串转换为描述其语音表示的字母数字模式。 @@ -1209,4 +1209,4 @@ DROP TRIGGER IF EXISTS trigger_insert_user; - [后端程序员必备:SQL 高性能优化指南!35+条优化建议立马 GET!](https://mp.weixin.qq.com/s/I-ZT3zGTNBZ6egS7T09jyQ) - [后端程序员必备:书写高质量 SQL 的 30 条建议](https://mp.weixin.qq.com/s?__biz=Mzg2OTA0Njk0OA==&mid=2247486461&idx=1&sn=60a22279196d084cc398936fe3b37772&chksm=cea24436f9d5cd20a4fa0e907590f3e700d7378b3f608d7b33bb52cfb96f503b7ccb65a1deed&token=1987003517&lang=zh_CN#rd) - \ No newline at end of file + diff --git a/docs/distributed-system/api-gateway.md b/docs/distributed-system/api-gateway.md index 46019c0b..89df1063 100644 --- a/docs/distributed-system/api-gateway.md +++ b/docs/distributed-system/api-gateway.md @@ -171,4 +171,4 @@ Shenyu 通过插件扩展功能,插件是 ShenYu 的灵魂,并且插件也 - API 网关 Kong 实战: - Spring Cloud Gateway 原理介绍和应用: - \ No newline at end of file + diff --git a/docs/distributed-system/distributed-configuration-center.md b/docs/distributed-system/distributed-configuration-center.md index 1c97bddb..2e00aec7 100644 --- a/docs/distributed-system/distributed-configuration-center.md +++ b/docs/distributed-system/distributed-configuration-center.md @@ -9,4 +9,4 @@ category: 分布式 - \ No newline at end of file + diff --git a/docs/distributed-system/distributed-id.md b/docs/distributed-system/distributed-id.md index ee1fcfd3..87497b2a 100644 --- a/docs/distributed-system/distributed-id.md +++ b/docs/distributed-system/distributed-id.md @@ -355,4 +355,4 @@ Tinyid 的优缺点这里就不分析了,结合数据库号段模式的优缺 不过,本文主要介绍的是分布式 ID 的理论知识。在实际的面试中,面试官可能会结合具体的业务场景来考察你对分布式 ID 的设计,你可以参考这篇文章:[分布式 ID 设计指南](./distributed-id-design)(对于实际工作中分布式 ID 的设计也非常有帮助)。 - \ No newline at end of file + diff --git a/docs/distributed-system/distributed-lock-implementations.md b/docs/distributed-system/distributed-lock-implementations.md index 9aff2844..73fe6059 100644 --- a/docs/distributed-system/distributed-lock-implementations.md +++ b/docs/distributed-system/distributed-lock-implementations.md @@ -367,4 +367,4 @@ private static class LockData 这篇文章我们介绍了实现分布式锁的两种常见方式。至于具体选择 Redis 还是 ZooKeeper 来实现分布式锁,还是要看业务的具体需求。如果对性能要求比较高的话,建议使用 Redis 实现分布式锁。如果对可靠性要求比较高的话,建议使用 ZooKeeper 实现分布式锁。 - \ No newline at end of file + diff --git a/docs/distributed-system/distributed-lock.md b/docs/distributed-system/distributed-lock.md index c6223170..2f7f0289 100644 --- a/docs/distributed-system/distributed-lock.md +++ b/docs/distributed-system/distributed-lock.md @@ -81,4 +81,4 @@ category: 分布式 - 分布式锁的应该具备的条件:互斥、高可用、可重入、高性能、非阻塞。 - 分布式锁的常见实现方式:关系型数据库比如 MySQL、分布式协调服务 ZooKeeper、分布式键值存储系统比如 Redis 、Etcd 。 - \ No newline at end of file + diff --git a/docs/distributed-system/distributed-process-coordination/zookeeper/zookeeper-in-action.md b/docs/distributed-system/distributed-process-coordination/zookeeper/zookeeper-in-action.md index b008d277..af6f3de5 100644 --- a/docs/distributed-system/distributed-process-coordination/zookeeper/zookeeper-in-action.md +++ b/docs/distributed-system/distributed-process-coordination/zookeeper/zookeeper-in-action.md @@ -294,4 +294,4 @@ zkClient.setData().forPath("/node1/00001","c++".getBytes());//更新节点数据 List childrenPaths = zkClient.getChildren().forPath("/node1"); ``` - \ No newline at end of file + diff --git a/docs/distributed-system/distributed-process-coordination/zookeeper/zookeeper-intro.md b/docs/distributed-system/distributed-process-coordination/zookeeper/zookeeper-intro.md index 29c29181..c0c6d11b 100644 --- a/docs/distributed-system/distributed-process-coordination/zookeeper/zookeeper-intro.md +++ b/docs/distributed-system/distributed-process-coordination/zookeeper/zookeeper-intro.md @@ -280,4 +280,4 @@ ZAB 协议包括两种基本的模式,分别是 - 《从 Paxos 到 ZooKeeper 分布式一致性原理与实践》 - \ No newline at end of file + diff --git a/docs/distributed-system/distributed-process-coordination/zookeeper/zookeeper-plus.md b/docs/distributed-system/distributed-process-coordination/zookeeper/zookeeper-plus.md index dd7219aa..4cdb7486 100644 --- a/docs/distributed-system/distributed-process-coordination/zookeeper/zookeeper-plus.md +++ b/docs/distributed-system/distributed-process-coordination/zookeeper/zookeeper-plus.md @@ -365,4 +365,4 @@ tag: 如果忘了可以回去看看再次理解一下,如果有疑问和建议欢迎提出 🤝🤝🤝。 - \ No newline at end of file + diff --git a/docs/distributed-system/distributed-transaction.md b/docs/distributed-system/distributed-transaction.md index 73e3122d..fa4c83c7 100644 --- a/docs/distributed-system/distributed-transaction.md +++ b/docs/distributed-system/distributed-transaction.md @@ -9,4 +9,4 @@ category: 分布式 - \ No newline at end of file + diff --git a/docs/distributed-system/protocol/cap-and-base-theorem.md b/docs/distributed-system/protocol/cap-and-base-theorem.md index 78ec3e3e..36a2fa54 100644 --- a/docs/distributed-system/protocol/cap-and-base-theorem.md +++ b/docs/distributed-system/protocol/cap-and-base-theorem.md @@ -141,9 +141,7 @@ CAP 理论这节我们也说过了: > 分布式一致性的 3 种级别: > > 1. **强一致性**:系统写入了什么,读出来的就是什么。 -> > 2. **弱一致性**:不一定可以读取到最新写入的值,也不保证多少时间之后读取到的数据是最新的,只是会尽量保证某个时刻达到数据一致的状态。 -> > 3. **最终一致性**:弱一致性的升级版,系统会保证在一定时间内达到数据一致的状态。 > > **业界比较推崇是最终一致性级别,但是某些对数据一致要求十分严格的场景比如银行转账还是要保证强一致性。** @@ -160,4 +158,4 @@ CAP 理论这节我们也说过了: **ACID 是数据库事务完整性的理论,CAP 是分布式系统设计理论,BASE 是 CAP 理论中 AP 方案的延伸。** - \ No newline at end of file + diff --git a/docs/distributed-system/protocol/gossip-protocl.md b/docs/distributed-system/protocol/gossip-protocl.md index fc4ba306..f6c7ecb1 100644 --- a/docs/distributed-system/protocol/gossip-protocl.md +++ b/docs/distributed-system/protocol/gossip-protocl.md @@ -142,4 +142,4 @@ Gossip 设计了两种可能的消息传播模式:**反熵(Anti-Entropy)** - 《分布式协议与算法实战》 - 《Redis 设计与实现》 - \ No newline at end of file + diff --git a/docs/distributed-system/protocol/paxos-algorithm.md b/docs/distributed-system/protocol/paxos-algorithm.md index 39453d91..45aaf72c 100644 --- a/docs/distributed-system/protocol/paxos-algorithm.md +++ b/docs/distributed-system/protocol/paxos-algorithm.md @@ -80,4 +80,4 @@ Basic Paxos 算法的仅能就单个值达成共识,为了能够对一系列 - https://zh.wikipedia.org/wiki/Paxos - 分布式系统中的一致性与共识算法:http://www.xuyasong.com/?p=1970 - \ No newline at end of file + diff --git a/docs/distributed-system/protocol/raft-algorithm.md b/docs/distributed-system/protocol/raft-algorithm.md index 2f85b72a..e61cc9b3 100644 --- a/docs/distributed-system/protocol/raft-algorithm.md +++ b/docs/distributed-system/protocol/raft-algorithm.md @@ -168,4 +168,4 @@ raft 的要求之一就是安全性不依赖于时间:系统不能仅仅因为 - https://github.com/ongardie/dissertation/blob/master/stanford.pdf - https://knowledge-sharing.gitbooks.io/raft/content/chapter5.html - \ No newline at end of file + diff --git a/docs/distributed-system/rpc/dubbo.md b/docs/distributed-system/rpc/dubbo.md index 436e08d4..3eaee38b 100644 --- a/docs/distributed-system/rpc/dubbo.md +++ b/docs/distributed-system/rpc/dubbo.md @@ -458,4 +458,4 @@ Dubbo 官方文档中还有一个关于这些[序列化协议的性能对比图] ![序列化协议的性能对比](https://oss.javaguide.cn/github/javaguide/distributed-system/rpc/dubbo-serialization-protocol-performance-comparison.png) - \ No newline at end of file + diff --git a/docs/distributed-system/rpc/http&rpc.md b/docs/distributed-system/rpc/http&rpc.md index ce381f18..7cd2b160 100644 --- a/docs/distributed-system/rpc/http&rpc.md +++ b/docs/distributed-system/rpc/http&rpc.md @@ -193,4 +193,4 @@ res = remoteFunc(req) - RPC 其实比 HTTP 出现的要早,且比目前主流的 HTTP1.1 性能要更好,所以大部分公司内部都还在使用 RPC。 - **HTTP2.0** 在 **HTTP1.1** 的基础上做了优化,性能可能比很多 RPC 协议都要好,但由于是这几年才出来的,所以也不太可能取代掉 RPC。 - \ No newline at end of file + diff --git a/docs/distributed-system/rpc/rpc-intro.md b/docs/distributed-system/rpc/rpc-intro.md index c0889546..b31a3e9e 100644 --- a/docs/distributed-system/rpc/rpc-intro.md +++ b/docs/distributed-system/rpc/rpc-intro.md @@ -138,4 +138,4 @@ Dubbo 也是 Spring Cloud Alibaba 里面的一个组件。 关于这个问题的详细答案,请看这篇文章:[有了 HTTP 协议,为什么还要有 RPC ?](http&rpc.md) 。 - \ No newline at end of file + diff --git a/docs/distributed-system/spring-cloud-gateway-questions.md b/docs/distributed-system/spring-cloud-gateway-questions.md index d6582625..1e6e8684 100644 --- a/docs/distributed-system/spring-cloud-gateway-questions.md +++ b/docs/distributed-system/spring-cloud-gateway-questions.md @@ -154,4 +154,4 @@ public class GlobalErrorWebExceptionHandler implements ErrorWebExceptionHandler - Creating a custom Spring Cloud Gateway Filter: - 全局异常处理: - \ No newline at end of file + diff --git a/docs/high-availability/fallback-and-circuit-breaker.md b/docs/high-availability/fallback-and-circuit-breaker.md index 8302f9d9..63bebb7a 100644 --- a/docs/high-availability/fallback-and-circuit-breaker.md +++ b/docs/high-availability/fallback-and-circuit-breaker.md @@ -7,4 +7,4 @@ category: 高可用 - \ No newline at end of file + diff --git a/docs/high-availability/high-availability-system-design.md b/docs/high-availability/high-availability-system-design.md index f2bc2df0..3c05f2b8 100644 --- a/docs/high-availability/high-availability-system-design.md +++ b/docs/high-availability/high-availability-system-design.md @@ -67,4 +67,4 @@ category: 高可用 - **定期检查/更换硬件:** 如果不是购买的云服务的话,定期还是需要对硬件进行一波检查的,对于一些需要更换或者升级的硬件,要及时更换或者升级。 - …… - \ No newline at end of file + diff --git a/docs/high-availability/limit-request.md b/docs/high-availability/limit-request.md index 6169a5ee..a7ba1192 100644 --- a/docs/high-availability/limit-request.md +++ b/docs/high-availability/limit-request.md @@ -210,4 +210,4 @@ Resilience4j 不仅提供限流,还提供了熔断、负载保护、自动重 - 超详细的 Guava RateLimiter 限流原理解析: - 实战 Spring Cloud Gateway 之限流篇 👍: - \ No newline at end of file + diff --git a/docs/high-availability/performance-test.md b/docs/high-availability/performance-test.md index a025dc07..2fc9bfc9 100644 --- a/docs/high-availability/performance-test.md +++ b/docs/high-availability/performance-test.md @@ -148,4 +148,4 @@ category: 高可用 5. 数据库索引使用是否合理? 6. …… - \ No newline at end of file + diff --git a/docs/high-availability/redundancy.md b/docs/high-availability/redundancy.md index e2c88b01..5cec473e 100644 --- a/docs/high-availability/redundancy.md +++ b/docs/high-availability/redundancy.md @@ -43,4 +43,4 @@ category: 高可用 不过,这些文章大多也都是在介绍概念知识。目前,网上还缺少真正介绍具体要如何去实践落地异地多活架构的资料。 - \ No newline at end of file + diff --git a/docs/high-availability/timeout-and-retry.md b/docs/high-availability/timeout-and-retry.md index 6b714ee5..8db69f11 100644 --- a/docs/high-availability/timeout-and-retry.md +++ b/docs/high-availability/timeout-and-retry.md @@ -78,4 +78,4 @@ category: 高可用 - 微服务之间调用超时的设置治理: - 超时、重试和抖动回退: - \ No newline at end of file + diff --git a/docs/high-performance/message-queue/disruptor-questions.md b/docs/high-performance/message-queue/disruptor-questions.md index 814e9f80..4833bd7c 100644 --- a/docs/high-performance/message-queue/disruptor-questions.md +++ b/docs/high-performance/message-queue/disruptor-questions.md @@ -137,4 +137,4 @@ CPU 缓存是通过将最近使用的数据存储在高速缓存中来实现更 - Disruptor 高性能之道-等待策略: - 《Java 并发编程实战》- 40 | 案例分析(三):高性能队列 Disruptor: - \ No newline at end of file + diff --git a/docs/high-performance/message-queue/kafka-questions-01.md b/docs/high-performance/message-queue/kafka-questions-01.md index 296d7eb6..68ca0dd3 100644 --- a/docs/high-performance/message-queue/kafka-questions-01.md +++ b/docs/high-performance/message-queue/kafka-questions-01.md @@ -438,4 +438,4 @@ private void customer(String message) { - Kafka 官方文档:https://kafka.apache.org/documentation/ - 极客时间—《Kafka 核心技术与实战》第 11 节:无消息丢失配置怎么实现? - \ No newline at end of file + diff --git a/docs/high-performance/message-queue/message-queue.md b/docs/high-performance/message-queue/message-queue.md index fb7d7d89..310b9a95 100644 --- a/docs/high-performance/message-queue/message-queue.md +++ b/docs/high-performance/message-queue/message-queue.md @@ -287,4 +287,4 @@ Pulsar 更新记录(可以直观看到项目是否还在维护):https://gi - KRaft: Apache Kafka Without ZooKeeper:https://developer.confluent.io/learn/kraft/ - 消息队列的使用场景是什么样的?:https://mp.weixin.qq.com/s/4V1jI6RylJr7Jr9JsQe73A - \ No newline at end of file + diff --git a/docs/high-performance/message-queue/rocketmq-questions.md b/docs/high-performance/message-queue/rocketmq-questions.md index b22c658c..b1334908 100644 --- a/docs/high-performance/message-queue/rocketmq-questions.md +++ b/docs/high-performance/message-queue/rocketmq-questions.md @@ -197,8 +197,6 @@ tag: 你可以看到图中生产者组中的生产者会向主题发送消息,而 **主题中存在多个队列**,生产者每次生产消息之后是指定主题中的某个队列发送消息的。 - - 每个主题中都有多个队列(分布在不同的 `Broker`中,如果是集群的话,`Broker`又分布在不同的服务器中),集群消费模式下,一个消费者集群多台机器共同消费一个 `topic` 的多个队列,**一个队列只会被一个消费者消费**。如果某个消费者挂掉,分组内其它消费者会接替挂掉的消费者继续消费。就像上图中 `Consumer1` 和 `Consumer2` 分别对应着两个队列,而 `Consumer3` 是没有队列对应的,所以一般来讲要控制 **消费者组中的消费者个数和主题中队列个数相同** 。 当然也可以消费者个数小于队列个数,只不过不太建议。如下图。 @@ -373,7 +371,7 @@ SimpleConsumer 是一种接口原子型的消费者类型,消息的获取、 一个来自官网的例子: ```java -// 消费示例:使用 SimpleConsumer 消费普通消息,主动获取消息处理并提交。 +// 消费示例:使用 SimpleConsumer 消费普通消息,主动获取消息处理并提交。 ClientServiceProvider provider = ClientServiceProvider.loadService(); String topic = "YourTopic"; FilterExpression filterExpression = new FilterExpression("YourFilterTag", FilterExpressionType.TAG); @@ -608,8 +606,6 @@ sendfile()跟 mmap()一样,也会减少一次 CPU 拷贝,但是它同时也 ![5](https://img1.imgtp.com/2023/08/15/jqLgCEBY.png) - - 如图,用户在发起 sendfile()调用时会发生切换 1,之后数据通过 DMA 拷贝到内核缓冲区,之后再将内核缓冲区的数据 CPU 拷贝到 Socket 缓冲区,最后拷贝到网卡,sendfile()返回,发生切换 2。发生了 3 次拷贝和两次切换。Java 也提供了相应 api: ```java @@ -725,4 +721,4 @@ emmm,是不是有一点复杂 🤣,看英文图片和英文文档的时候 等等。。。 - \ No newline at end of file + diff --git a/docs/high-performance/read-and-write-separation-and-library-subtable.md b/docs/high-performance/read-and-write-separation-and-library-subtable.md index 19a0c04d..3f9f9072 100644 --- a/docs/high-performance/read-and-write-separation-and-library-subtable.md +++ b/docs/high-performance/read-and-write-separation-and-library-subtable.md @@ -266,4 +266,4 @@ ShardingSphere 的优势如下(摘自 ShardingSphere 官方文档: \ No newline at end of file + diff --git a/docs/high-performance/sql-optimization.md b/docs/high-performance/sql-optimization.md index 3f10f6dc..9aa94dfd 100644 --- a/docs/high-performance/sql-optimization.md +++ b/docs/high-performance/sql-optimization.md @@ -16,4 +16,4 @@ head: - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/advanced-programmer/20-bad-habits-of-bad-programmers.md b/docs/high-quality-technical-articles/advanced-programmer/20-bad-habits-of-bad-programmers.md index db1f2e5e..c1bc95f5 100644 --- a/docs/high-quality-technical-articles/advanced-programmer/20-bad-habits-of-bad-programmers.md +++ b/docs/high-quality-technical-articles/advanced-programmer/20-bad-habits-of-bad-programmers.md @@ -145,4 +145,4 @@ tag: 希望你我可以有则改之,无则加勉。 - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/advanced-programmer/seven-tips-for-becoming-an-advanced-programmer.md b/docs/high-quality-technical-articles/advanced-programmer/seven-tips-for-becoming-an-advanced-programmer.md index 344a2982..eca78e67 100644 --- a/docs/high-quality-technical-articles/advanced-programmer/seven-tips-for-becoming-an-advanced-programmer.md +++ b/docs/high-quality-technical-articles/advanced-programmer/seven-tips-for-becoming-an-advanced-programmer.md @@ -106,4 +106,4 @@ tag: 而高级的程序员往往都会在一件比较大的事情做完之后总结一下,做个 ppt,写个博客啥的记录下来。这样既对自己的工作是一个归纳,也可以分享给其它同学,促进团队的共同成长。 - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/advanced-programmer/ten-years-of-dachang-growth-road.md b/docs/high-quality-technical-articles/advanced-programmer/ten-years-of-dachang-growth-road.md index 4df141c0..56da00e3 100644 --- a/docs/high-quality-technical-articles/advanced-programmer/ten-years-of-dachang-growth-road.md +++ b/docs/high-quality-technical-articles/advanced-programmer/ten-years-of-dachang-growth-road.md @@ -135,4 +135,4 @@ tag: 以上就是我对互联网从业技术人员十年成长之路的心得,希望在你困惑和关键选择的时候可以帮助到你。如果我的只言片语能够在未来的某个时间帮助到你哪怕一点,那将是我莫大的荣幸。 - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/advanced-programmer/the-growth-strategy-of-the-technological-giant.md b/docs/high-quality-technical-articles/advanced-programmer/the-growth-strategy-of-the-technological-giant.md index 84d9531d..f5b9d5a9 100644 --- a/docs/high-quality-technical-articles/advanced-programmer/the-growth-strategy-of-the-technological-giant.md +++ b/docs/high-quality-technical-articles/advanced-programmer/the-growth-strategy-of-the-technological-giant.md @@ -204,4 +204,4 @@ Brendan Gregg,Jay Kreps 和 Brad Traversy 三个人走的技术路线各不相 > > 实现战略目标,就像种树一样。刚开始只是一个小根芽,树干还没有长出来;树干长出来了,枝叶才能慢慢长出来;树枝长出来,然后才能开花和结果。刚开始种树的时候,只管栽培灌溉,别老是纠结枝什么时候长出来,花什么时候开,果实什么时候结出来。纠结有什么好处呢?只要你坚持投入栽培,还怕没有枝叶花实吗? - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/advanced-programmer/thinking-about-technology-and-business-after-five-years-of-work.md b/docs/high-quality-technical-articles/advanced-programmer/thinking-about-technology-and-business-after-five-years-of-work.md index b330d245..1368bf74 100644 --- a/docs/high-quality-technical-articles/advanced-programmer/thinking-about-technology-and-business-after-five-years-of-work.md +++ b/docs/high-quality-technical-articles/advanced-programmer/thinking-about-technology-and-business-after-five-years-of-work.md @@ -107,4 +107,5 @@ tag: 人的精力是有限的,而且面对三十这个天花板,各种事件也会接连而至,在职场中学会合理安排时间并不断提升核心能力,这样才能保证自己的竞争力。 职场就像苦海无边,回首望去可能也没有岸边停泊,但是要具有换船的能力或者有个小木筏也就大差不差了。 - \ No newline at end of file + + diff --git a/docs/high-quality-technical-articles/interview/how-to-examine-the-technical-ability-of-programmers-in-the-first-test-of-technology.md b/docs/high-quality-technical-articles/interview/how-to-examine-the-technical-ability-of-programmers-in-the-first-test-of-technology.md index 2050604e..19ce9898 100644 --- a/docs/high-quality-technical-articles/interview/how-to-examine-the-technical-ability-of-programmers-in-the-first-test-of-technology.md +++ b/docs/high-quality-technical-articles/interview/how-to-examine-the-technical-ability-of-programmers-in-the-first-test-of-technology.md @@ -343,4 +343,4 @@ tag: - [技术面试官的 9 大误区](https://zhuanlan.zhihu.com/p/51404304) - [如何当一个好的面试官?](https://www.zhihu.com/question/26240321) - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/interview/my-personal-experience-in-2021.md b/docs/high-quality-technical-articles/interview/my-personal-experience-in-2021.md index 6709c4f7..204be1f5 100644 --- a/docs/high-quality-technical-articles/interview/my-personal-experience-in-2021.md +++ b/docs/high-quality-technical-articles/interview/my-personal-experience-in-2021.md @@ -200,4 +200,4 @@ tag: - 面试中的笔试和前面的笔试风格不同,面试笔试题目不太难,但是考察是冷静思考,代码优雅,没有 bug,先思考清楚!!!在写!!! - 在描述项目的难点的时候,不要去聊文档调研是难点,回答这部分问题更应该是技术上的难点,最后通过了什么技术解决了这个问题,这部分技术可以让面试官来更多提问以便知道自己的技术能力。 - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/interview/screen-candidates-for-packaging.md b/docs/high-quality-technical-articles/interview/screen-candidates-for-packaging.md index 89e04b9b..34865443 100644 --- a/docs/high-quality-technical-articles/interview/screen-candidates-for-packaging.md +++ b/docs/high-quality-technical-articles/interview/screen-candidates-for-packaging.md @@ -117,4 +117,4 @@ tag: 写在最后,笔者认为在招聘途中,并不是不允许求职者包装,但是尽可能满足能筹平衡。虽然这篇文章没有完美的结尾,但是笔者提供了面试失败的各种经验。笔者最终招到了如意的小伙伴。也希望所有技术面试官早日找到符合自己产品发展的 IT 伙伴。 - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/interview/some-secrets-about-alibaba-interview.md b/docs/high-quality-technical-articles/interview/some-secrets-about-alibaba-interview.md index 796422b0..e821f031 100644 --- a/docs/high-quality-technical-articles/interview/some-secrets-about-alibaba-interview.md +++ b/docs/high-quality-technical-articles/interview/some-secrets-about-alibaba-interview.md @@ -118,4 +118,4 @@ action,action,action ,重要的事情说三遍,做技术的不可能光 最后,祝愿优秀的你能找到自己理想的工作! - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/interview/summary-of-spring-recruitment.md b/docs/high-quality-technical-articles/interview/summary-of-spring-recruitment.md index 112670ee..b3d215d5 100644 --- a/docs/high-quality-technical-articles/interview/summary-of-spring-recruitment.md +++ b/docs/high-quality-technical-articles/interview/summary-of-spring-recruitment.md @@ -162,4 +162,4 @@ Java 卷吗?毫无疑问,很卷,我个人认为开发属于没有什么门 惟愿诸君,前程似锦! - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/interview/technical-preliminary-preparation.md b/docs/high-quality-technical-articles/interview/technical-preliminary-preparation.md index 593aec5c..6a7d200e 100644 --- a/docs/high-quality-technical-articles/interview/technical-preliminary-preparation.md +++ b/docs/high-quality-technical-articles/interview/technical-preliminary-preparation.md @@ -213,4 +213,4 @@ tag: 这一点是我当了技术面试官才领会到的。当然,并不是每位技术面试官都是这么想的,但我觉得这应该是个更合适的方式。 - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/interview/the-experience-and-thinking-of-an-interview-experienced-by-an-older-programmer.md b/docs/high-quality-technical-articles/interview/the-experience-and-thinking-of-an-interview-experienced-by-an-older-programmer.md index 1cb88123..e86d7853 100644 --- a/docs/high-quality-technical-articles/interview/the-experience-and-thinking-of-an-interview-experienced-by-an-older-programmer.md +++ b/docs/high-quality-technical-articles/interview/the-experience-and-thinking-of-an-interview-experienced-by-an-older-programmer.md @@ -359,4 +359,4 @@ ZOOM 的一位面试官或许是我见过的所有面试官中最差劲的。共 面试,其实也是一段工作经历。 - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/interview/the-experience-of-get-offer-from-over-20-big-companies.md b/docs/high-quality-technical-articles/interview/the-experience-of-get-offer-from-over-20-big-companies.md index 5f163798..a7541fb8 100644 --- a/docs/high-quality-technical-articles/interview/the-experience-of-get-offer-from-over-20-big-companies.md +++ b/docs/high-quality-technical-articles/interview/the-experience-of-get-offer-from-over-20-big-companies.md @@ -196,4 +196,4 @@ tag: 总而言之,为了自己想要争取的东西,做好足够的准备总是没有坏处的。祝愿大家能成为`π`型人才,获得想要的`offer`! - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/personal-experience/8-years-programmer-work-summary.md b/docs/high-quality-technical-articles/personal-experience/8-years-programmer-work-summary.md index cad4dddc..948f7c5d 100644 --- a/docs/high-quality-technical-articles/personal-experience/8-years-programmer-work-summary.md +++ b/docs/high-quality-technical-articles/personal-experience/8-years-programmer-work-summary.md @@ -233,4 +233,4 @@ _PS:有几个问题先在这里解释一下,评论就不一一回复了_ 好了 7 年多,近 8 年的职场讲完了,不管过去如何,未来还是要继续努力,希望看到这篇文章觉得有帮助的朋友,可以帮忙点个推荐,这样可能更多的人看到,也许可以避免更多的人犯我犯的错误。另外欢迎私信或者其他方式交流(某 Xin 号,jingyewandeng),可以讨论职场经验,方向,我也可以帮忙改简历(免费啊),不用怕打扰,能帮助别人是一项很有成绩感的事,并且过程中也会有收获,程序员也不要太腼腆呵呵 - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/personal-experience/four-year-work-in-tencent-summary.md b/docs/high-quality-technical-articles/personal-experience/four-year-work-in-tencent-summary.md index 5f2b4aea..465929cc 100644 --- a/docs/high-quality-technical-articles/personal-experience/four-year-work-in-tencent-summary.md +++ b/docs/high-quality-technical-articles/personal-experience/four-year-work-in-tencent-summary.md @@ -106,4 +106,4 @@ PS:还好以前有奖杯,不然一点念想都没了。(现在腾讯似乎 腾讯的四年,是我的第一份工作经历,认识了很多厉害的人,学到了很多。最后自己主动离开,也算走的体面(即使损失了大礼包),还是感谢腾讯。 - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/personal-experience/huawei-od-275-days.md b/docs/high-quality-technical-articles/personal-experience/huawei-od-275-days.md index b8c70371..9bacc732 100644 --- a/docs/high-quality-technical-articles/personal-experience/huawei-od-275-days.md +++ b/docs/high-quality-technical-articles/personal-experience/huawei-od-275-days.md @@ -336,4 +336,4 @@ blabla 有少量的基础问题和一面有重复,还有几个和大数据相 感受比较深的是,作为程序员,还是要自我驱动,努力提升个人技术能力,横向纵向都要扩充,这样才能走得长远。 - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/personal-experience/two-years-of-back-end-develop--experience-in-didi-and-toutiao.md b/docs/high-quality-technical-articles/personal-experience/two-years-of-back-end-develop--experience-in-didi-and-toutiao.md index df7a61a1..d3296a4e 100644 --- a/docs/high-quality-technical-articles/personal-experience/two-years-of-back-end-develop--experience-in-didi-and-toutiao.md +++ b/docs/high-quality-technical-articles/personal-experience/two-years-of-back-end-develop--experience-in-didi-and-toutiao.md @@ -149,4 +149,4 @@ tag: 最后祝大家都能找到心仪的工作,快乐工作,幸福生活,广阔天地,大有作为。 - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/programmer/efficient-book-publishing-and-practice-guide.md b/docs/high-quality-technical-articles/programmer/efficient-book-publishing-and-practice-guide.md index 4c223ee6..9501aece 100644 --- a/docs/high-quality-technical-articles/programmer/efficient-book-publishing-and-practice-guide.md +++ b/docs/high-quality-technical-articles/programmer/efficient-book-publishing-and-practice-guide.md @@ -139,4 +139,4 @@ tag: 从上文里大家可以看到,在出书前期,联系出版社编辑和定选题并不难,如果要写案例书,那么在参考别人内容的基础上,要写完一般书可能也不是高不可攀的事情。甚至可以这样说,出书是个体力活,只要坚持,要出本书并不难,只是你愿不愿意坚持下去的问题。但一旦你有了属于自己的技术书,那么在找工作时,你就能自信地和面试官说你是这方面的专家,在你的视频、公众号和文字里,你也能正大光明地说,你是计算机图书的作者。更为重要的是,和名校、大厂经历一样,属于你的技术书同样是证明程序员能力的重要证据,当你通过出书有效整合了相关方面的知识体系后,那么在这方面,不管是找工作,或者是干私活,或者是接项目做,你都能理直气壮地和别人说:我能行! - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/programmer/how-do-programmers-publish-a-technical-book.md b/docs/high-quality-technical-articles/programmer/how-do-programmers-publish-a-technical-book.md index 75d3182c..20c7ed1b 100644 --- a/docs/high-quality-technical-articles/programmer/how-do-programmers-publish-a-technical-book.md +++ b/docs/high-quality-technical-articles/programmer/how-do-programmers-publish-a-technical-book.md @@ -92,4 +92,4 @@ tag: 那么如何让出书带来的利益最大化呢?第一可以靠这进大厂,面试时有自己的书绝对是加分项。第二可以用这个去各大网站开专栏,录视频,或者开公众号,毕竟有出版社的背书,能更让别人信服你的能力。第三更得用写书时积累的学习方法和上进的态势继续专研更高深技术,技术有了,不仅能到大厂挣更多的钱,还能通过企业培训等方式更高效地挣钱。 - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/readme.md b/docs/high-quality-technical-articles/readme.md index 68eb6111..6950676d 100644 --- a/docs/high-quality-technical-articles/readme.md +++ b/docs/high-quality-technical-articles/readme.md @@ -41,4 +41,4 @@ - [32 条总结教你提升职场经验](./work/32-tips-improving-career.md) - [聊聊大厂的绩效考核](./work/employee-performance.md) - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/work/32-tips-improving-career.md b/docs/high-quality-technical-articles/work/32-tips-improving-career.md index 8c5cca97..78b0e66b 100644 --- a/docs/high-quality-technical-articles/work/32-tips-improving-career.md +++ b/docs/high-quality-technical-articles/work/32-tips-improving-career.md @@ -69,4 +69,4 @@ tag: - Leader 的重要职责是识别团队需要被做的事情,并坚定信念,使众人行,越是艰难的时候越要坚定; - Leader 应该让自己遇到的每个人都感觉自己很重要、被需要。 - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/work/employee-performance.md b/docs/high-quality-technical-articles/work/employee-performance.md index 9e366dcd..c9371583 100644 --- a/docs/high-quality-technical-articles/work/employee-performance.md +++ b/docs/high-quality-technical-articles/work/employee-performance.md @@ -131,4 +131,4 @@ A 和 C 属于绩效的两个极端,背后的逻辑类似,反着理解即可 如果这篇文章让你有一点启发,来个点赞和在看呀!我是武哥,我们下期见! - \ No newline at end of file + diff --git a/docs/high-quality-technical-articles/work/get-into-work-mode-quickly-when-you-join-a-company.md b/docs/high-quality-technical-articles/work/get-into-work-mode-quickly-when-you-join-a-company.md index ddb87db3..71b928fb 100644 --- a/docs/high-quality-technical-articles/work/get-into-work-mode-quickly-when-you-join-a-company.md +++ b/docs/high-quality-technical-articles/work/get-into-work-mode-quickly-when-you-join-a-company.md @@ -93,4 +93,4 @@ tag: 最后我们用一张思维导图来回顾一下这篇文章的内容。如果你觉得这篇文章对你有所帮助,可以关注文末公众号,我会经常分享一些自己成长过程中的经验与心得,与大家一起学习与进步。 - \ No newline at end of file + diff --git a/docs/interview-preparation/teach-you-how-to-prepare-for-the-interview-hand-in-hand.md b/docs/interview-preparation/teach-you-how-to-prepare-for-the-interview-hand-in-hand.md index 3cd30d6f..2e813f5e 100644 --- a/docs/interview-preparation/teach-you-how-to-prepare-for-the-interview-hand-in-hand.md +++ b/docs/interview-preparation/teach-you-how-to-prepare-for-the-interview-hand-in-hand.md @@ -207,4 +207,3 @@ Java 后端面试复习的重点请看这篇文章:[Java 面试重点总结( 6. 岗位匹配度很重要。校招通常会对你的项目经历的研究方向比较宽容,即使你的项目经历和对应公司的具体业务没有关系,影响其实也并不大。社招的话就不一样了,毕竟公司是要招聘可以直接来干活的人,你有相关的经验,公司会比较省事。 7. 面试之后及时复盘。面试就像是一场全新的征程,失败和胜利都是平常之事。所以,劝各位不要因为面试失败而灰心、丧失斗志。也不要因为面试通过而沾沾自喜,等待你的将是更美好的未来,继续加油! - diff --git a/docs/java/basis/bigdecimal.md b/docs/java/basis/bigdecimal.md index 8c2d368a..54e3ab3d 100644 --- a/docs/java/basis/bigdecimal.md +++ b/docs/java/basis/bigdecimal.md @@ -351,7 +351,7 @@ public class BigDecimalUtil { } ``` -相关 issue:[建议对保留规则设置为 RoundingMode.HALF_EVEN,即四舍六入五成双]([#2129](https://github.com/Snailclimb/JavaGuide/issues/2129)) 。 +相关 issue:[建议对保留规则设置为 RoundingMode.HALF_EVEN,即四舍六入五成双](<[#2129](https://github.com/Snailclimb/JavaGuide/issues/2129)>) 。 ![RoundingMode.HALF_EVEN](https://oss.javaguide.cn/github/javaguide/java/basis/RoundingMode.HALF_EVEN.png) diff --git a/docs/java/basis/generics-and-wildcards.md b/docs/java/basis/generics-and-wildcards.md index ee66b2e8..f65781e0 100644 --- a/docs/java/basis/generics-and-wildcards.md +++ b/docs/java/basis/generics-and-wildcards.md @@ -17,4 +17,4 @@ tag: - \ No newline at end of file + diff --git a/docs/java/basis/java-basic-questions-01.md b/docs/java/basis/java-basic-questions-01.md index 4c6b53a9..ebefbe84 100644 --- a/docs/java/basis/java-basic-questions-01.md +++ b/docs/java/basis/java-basic-questions-01.md @@ -35,7 +35,7 @@ head: “Write Once, Run Anywhere(一次编写,随处运行)”这句宣传口号,真心经典,流传了好多年!以至于,直到今天,依然有很多人觉得跨平台是 Java 语言最大的优势。实际上,跨平台已经不是 Java 最大的卖点了,各种 JDK 新特性也不是。目前市面上虚拟化技术已经非常成熟,比如你通过 Docker 就很容易实现跨平台了。在我看来,Java 强大的生态才是! -### Java SE vs Java EE +### Java SE vs Java EE - Java SE(Java Platform,Standard Edition): Java 平台标准版,Java 编程语言的基础,它包含了支持 Java 应用程序开发和运行的核心类库以及虚拟机等核心组件。Java SE 可以用于构建桌面应用程序或简单的服务器应用程序。 - Java EE(Java Platform, Enterprise Edition ):Java 平台企业版,建立在 Java SE 的基础上,包含了支持企业级应用程序开发和部署的标准和规范(比如 Servlet、JSP、EJB、JDBC、JPA、JTA、JavaMail、JMS)。 Java EE 可以用于构建分布式、可移植、健壮、可伸缩和安全的服务端 Java 应用程序,例如 Web 应用程序。 @@ -157,9 +157,7 @@ JDK 9 引入了一种新的编译模式 **AOT(Ahead of Time Compilation)** 。 > 答: > > 1. OpenJDK 是开源的,开源意味着你可以对它根据你自己的需要进行修改、优化,比如 Alibaba 基于 OpenJDK 开发了 Dragonwell8:[https://github.com/alibaba/dragonwell8](https://github.com/alibaba/dragonwell8) -> > 2. OpenJDK 是商业免费的(这也是为什么通过 yum 包管理器上默认安装的 JDK 是 OpenJDK 而不是 Oracle JDK)。虽然 Oracle JDK 也是商业免费(比如 JDK 8),但并不是所有版本都是免费的。 -> > 3. OpenJDK 更新频率更快。Oracle JDK 一般是每 6 个月发布一个新版本,而 OpenJDK 一般是每 3 个月发布一个新版本。(现在你知道为啥 Oracle JDK 更稳定了吧,先在 OpenJDK 试试水,把大部分问题都解决掉了才在 Oracle JDK 上发布) > > 基于以上这些原因,OpenJDK 还是有存在的必要的! @@ -408,16 +406,16 @@ Java 中有 8 种基本数据类型,分别为: 这 8 种基本数据类型的默认值以及所占空间的大小如下: -| 基本类型 | 位数 | 字节 | 默认值 | 取值范围 | -| :-------- | :--- | :--- | :------ | ------------------------------------------------------------ | -| `byte` | 8 | 1 | 0 | -128 ~ 127 | -| `short` | 16 | 2 | 0 | -32768(-2^15) ~ 32767(2^15 - 1) | -| `int` | 32 | 4 | 0 | -2147483648 ~ 2147483647 | +| 基本类型 | 位数 | 字节 | 默认值 | 取值范围 | +| :-------- | :--- | :--- | :------ | -------------------------------------------------------------- | +| `byte` | 8 | 1 | 0 | -128 ~ 127 | +| `short` | 16 | 2 | 0 | -32768(-2^15) ~ 32767(2^15 - 1) | +| `int` | 32 | 4 | 0 | -2147483648 ~ 2147483647 | | `long` | 64 | 8 | 0L | -9223372036854775808(-2^63) ~ 9223372036854775807(2^63 -1) | -| `char` | 16 | 2 | 'u0000' | 0 ~ 65535(2^16 - 1) | -| `float` | 32 | 4 | 0f | 1.4E-45 ~ 3.4028235E38 | -| `double` | 64 | 8 | 0d | 4.9E-324 ~ 1.7976931348623157E308 | -| `boolean` | 1 | | false | true、false | +| `char` | 16 | 2 | 'u0000' | 0 ~ 65535(2^16 - 1) | +| `float` | 32 | 4 | 0f | 1.4E-45 ~ 3.4028235E38 | +| `double` | 64 | 8 | 0d | 4.9E-324 ~ 1.7976931348623157E308 | +| `boolean` | 1 | | false | true、false | 可以看到,像 `byte`、`short`、`int`、`long`能表示的最大正数都减 1 了。这是为什么呢?这是因为在二进制补码表示法中,最高位是用来表示符号的(0 表示正数,1 表示负数),其余位表示数值部分。所以,如果我们要表示最大的正数,我们需要把除了最高位之外的所有位都设为 1。如果我们再加 1,就会导致溢出,变成一个负数。 diff --git a/docs/java/basis/java-basic-questions-02.md b/docs/java/basis/java-basic-questions-02.md index cc6af72f..5bc1a497 100644 --- a/docs/java/basis/java-basic-questions-02.md +++ b/docs/java/basis/java-basic-questions-02.md @@ -785,4 +785,4 @@ public static String getStr() { - 深入解析 String#intern: - R 大(RednaxelaFX)关于常量折叠的回答:https://www.zhihu.com/question/55976094/answer/147302764 - \ No newline at end of file + diff --git a/docs/java/basis/java-basic-questions-03.md b/docs/java/basis/java-basic-questions-03.md index b183a3d3..d744d067 100644 --- a/docs/java/basis/java-basic-questions-03.md +++ b/docs/java/basis/java-basic-questions-03.md @@ -572,4 +572,4 @@ Java 中最常用的语法糖主要有泛型、自动拆装箱、变长参数、 关于这些语法糖的详细解读,请看这篇文章 [Java 语法糖详解](./syntactic-sugar.md) 。 - \ No newline at end of file + diff --git a/docs/java/basis/java-keyword-summary.md b/docs/java/basis/java-keyword-summary.md index 75dec807..e7a6b4f4 100644 --- a/docs/java/basis/java-keyword-summary.md +++ b/docs/java/basis/java-keyword-summary.md @@ -306,4 +306,4 @@ public class Test { - https://www.cnblogs.com/chenssy/p/3388487.html - https://www.cnblogs.com/Qian123/p/5713440.html - \ No newline at end of file + diff --git a/docs/java/basis/proxy.md b/docs/java/basis/proxy.md index fead2be1..85902688 100644 --- a/docs/java/basis/proxy.md +++ b/docs/java/basis/proxy.md @@ -401,4 +401,4 @@ after method send 文中涉及到的所有源码,你可以在这里找到:[https://github.com/Snailclimb/guide-rpc-framework-learning/tree/master/src/main/java/github/javaguide/proxy](https://github.com/Snailclimb/guide-rpc-framework-learning/tree/master/src/main/java/github/javaguide/proxy) 。 - \ No newline at end of file + diff --git a/docs/java/basis/serialization.md b/docs/java/basis/serialization.md index 4b4a4cfb..406a7ce3 100644 --- a/docs/java/basis/serialization.md +++ b/docs/java/basis/serialization.md @@ -222,4 +222,4 @@ Kryo 是专门针对 Java 语言序列化方式并且性能非常好,如果你 除了我上面介绍到的序列化方式的话,还有像 Thrift,Avro 这些。 - \ No newline at end of file + diff --git a/docs/java/basis/spi.md b/docs/java/basis/spi.md index 8919d69e..baada46f 100644 --- a/docs/java/basis/spi.md +++ b/docs/java/basis/spi.md @@ -559,4 +559,4 @@ public class MyServiceLoader { 1. 遍历加载所有的实现类,这样效率还是相对较低的; 2. 当多个 `ServiceLoader` 同时 `load` 时,会有并发问题。 - \ No newline at end of file + diff --git a/docs/java/basis/syntactic-sugar.md b/docs/java/basis/syntactic-sugar.md index 1b09df81..3cc1831b 100644 --- a/docs/java/basis/syntactic-sugar.md +++ b/docs/java/basis/syntactic-sugar.md @@ -809,4 +809,4 @@ Iterator 是工作在一个独立的线程中,并且拥有一个 mutex 锁。 有了这些语法糖,我们在日常开发的时候可以大大提升效率,但是同时也要避过度使用。使用之前最好了解下原理,避免掉坑。 - \ No newline at end of file + diff --git a/docs/java/basis/why-there-only-value-passing-in-java.md b/docs/java/basis/why-there-only-value-passing-in-java.md index 8f439773..e9f9a7c2 100644 --- a/docs/java/basis/why-there-only-value-passing-in-java.md +++ b/docs/java/basis/why-there-only-value-passing-in-java.md @@ -216,4 +216,4 @@ Java 中将实参传递给方法(或函数)的方式是 **值传递**: - [Oracle Java Tutorials - Passing Information to a Method or a Constructor](https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html) - [Interview with James Gosling, Father of Java](https://mappingthejourney.com/single-post/2017/06/29/episode-3-interview-with-james-gosling-father-of-java/) - \ No newline at end of file + diff --git a/docs/java/collection/arrayblockingqueue-source-code.md b/docs/java/collection/arrayblockingqueue-source-code.md index 49c127eb..3a96767e 100644 --- a/docs/java/collection/arrayblockingqueue-source-code.md +++ b/docs/java/collection/arrayblockingqueue-source-code.md @@ -771,4 +771,4 @@ public boolean contains(Object o) { - 深入理解 Java 系列 | BlockingQueue 用法详解: - 深入浅出阻塞队列 BlockingQueue 及其典型实现 ArrayBlockingQueue: - 并发编程大扫盲:ArrayBlockingQueue 底层原理和实战: - \ No newline at end of file + diff --git a/docs/java/collection/arraylist-source-code.md b/docs/java/collection/arraylist-source-code.md index 194878ce..30d80f5b 100644 --- a/docs/java/collection/arraylist-source-code.md +++ b/docs/java/collection/arraylist-source-code.md @@ -961,4 +961,4 @@ public class EnsureCapacityTest { 通过运行结果,我们可以看出向 `ArrayList` 添加大量元素之前使用`ensureCapacity` 方法可以提升性能。不过,这个性能差距几乎可以忽略不计。而且,实际项目根本也不可能往 `ArrayList` 里面添加这么多元素。 - \ No newline at end of file + diff --git a/docs/java/collection/concurrent-hash-map-source-code.md b/docs/java/collection/concurrent-hash-map-source-code.md index 148e70a0..9a3a4041 100644 --- a/docs/java/collection/concurrent-hash-map-source-code.md +++ b/docs/java/collection/concurrent-hash-map-source-code.md @@ -590,4 +590,4 @@ Java8 中的 `ConcurrentHashMap` 使用的 `Synchronized` 锁加 CAS 的机制 有些同学可能对 `Synchronized` 的性能存在疑问,其实 `Synchronized` 锁自从引入锁升级策略后,性能不再是问题,有兴趣的同学可以自己了解下 `Synchronized` 的**锁升级**。 - \ No newline at end of file + diff --git a/docs/java/collection/copyonwritearraylist-source-code.md b/docs/java/collection/copyonwritearraylist-source-code.md index b8978af0..6c2d6140 100644 --- a/docs/java/collection/copyonwritearraylist-source-code.md +++ b/docs/java/collection/copyonwritearraylist-source-code.md @@ -314,5 +314,4 @@ System.out.println("列表清空后为:" + list); 列表清空后为:[] ``` - - \ No newline at end of file + diff --git a/docs/java/collection/hashmap-source-code.md b/docs/java/collection/hashmap-source-code.md index 8192a293..a4f92b8a 100644 --- a/docs/java/collection/hashmap-source-code.md +++ b/docs/java/collection/hashmap-source-code.md @@ -266,7 +266,6 @@ HashMap 只提供了 put 用于添加元素,putVal 方法只是给 put 方法 ![ ](https://oss.javaguide.cn/github/javaguide/database/sql/put.png) - ```java public V put(K key, V value) { return putVal(hash(key), key, value, false, true); @@ -499,7 +498,6 @@ final Node[] resize() { } ``` - ## HashMap 常用方法测试 ```java @@ -576,4 +574,4 @@ public class HashMapDemo { } ``` - \ No newline at end of file + diff --git a/docs/java/collection/java-collection-precautions-for-use.md b/docs/java/collection/java-collection-precautions-for-use.md index 05f6a45f..e636ff5a 100644 --- a/docs/java/collection/java-collection-precautions-for-use.md +++ b/docs/java/collection/java-collection-precautions-for-use.md @@ -438,4 +438,4 @@ Integer[] array = {1, 2, 3}; List list = List.of(array); ``` - \ No newline at end of file + diff --git a/docs/java/collection/java-collection-questions-01.md b/docs/java/collection/java-collection-questions-01.md index 560d1abf..1c0a4448 100644 --- a/docs/java/collection/java-collection-questions-01.md +++ b/docs/java/collection/java-collection-questions-01.md @@ -490,4 +490,4 @@ Java 中常用的阻塞队列实现类有以下几种: - 锁是否分离: `ArrayBlockingQueue`中的锁是没有分离的,即生产和消费用的是同一个锁;`LinkedBlockingQueue`中的锁是分离的,即生产用的是`putLock`,消费是`takeLock`,这样可以防止生产者和消费者线程之间的锁争夺。 - 内存占用:`ArrayBlockingQueue` 需要提前分配数组内存,而 `LinkedBlockingQueue` 则是动态分配链表节点内存。这意味着,`ArrayBlockingQueue` 在创建时就会占用一定的内存空间,且往往申请的内存比实际所用的内存更大,而`LinkedBlockingQueue` 则是根据元素的增加而逐渐占用内存空间。 - \ No newline at end of file + diff --git a/docs/java/collection/java-collection-questions-02.md b/docs/java/collection/java-collection-questions-02.md index 790a5493..190c928e 100644 --- a/docs/java/collection/java-collection-questions-02.md +++ b/docs/java/collection/java-collection-questions-02.md @@ -65,11 +65,11 @@ head: 如果你看过 `HashSet` 源码的话就应该知道:`HashSet` 底层就是基于 `HashMap` 实现的。(`HashSet` 的源码非常非常少,因为除了 `clone()`、`writeObject()`、`readObject()`是 `HashSet` 自己不得不实现之外,其他方法都是直接调用 `HashMap` 中的方法。 -| `HashMap` | `HashSet` | -| :------------------------------------: | :----------------------------------------------------------: | -| 实现了 `Map` 接口 | 实现 `Set` 接口 | -| 存储键值对 | 仅存储对象 | -| 调用 `put()`向 map 中添加元素 | 调用 `add()`方法向 `Set` 中添加元素 | +| `HashMap` | `HashSet` | +| :------------------------------------: | :----------------------------------------------------------------------------------------------------------------------: | +| 实现了 `Map` 接口 | 实现 `Set` 接口 | +| 存储键值对 | 仅存储对象 | +| 调用 `put()`向 map 中添加元素 | 调用 `add()`方法向 `Set` 中添加元素 | | `HashMap` 使用键(Key)计算 `hashcode` | `HashSet` 使用成员对象来计算 `hashcode` 值,对于两个对象来说 `hashcode` 可能相同,所以`equals()`方法用来判断对象的相等性 | ### HashMap 和 TreeMap 区别 @@ -590,4 +590,4 @@ synchronizedMap(Map m) //返回由指定映射支持的同步(线程安 synchronizedSet(Set s) //返回指定 set 支持的同步(线程安全的)set。 ``` - \ No newline at end of file + diff --git a/docs/java/collection/linkedlist-source-code.md b/docs/java/collection/linkedlist-source-code.md index 1cbce3a4..9cd4151c 100644 --- a/docs/java/collection/linkedlist-source-code.md +++ b/docs/java/collection/linkedlist-source-code.md @@ -513,4 +513,5 @@ System.out.println("清空后的链表:" + list); 链表长度:2 清空后的链表:[] ``` - \ No newline at end of file + + diff --git a/docs/java/collection/priorityqueue-source-code.md b/docs/java/collection/priorityqueue-source-code.md index c9bc72c2..b38cae9b 100644 --- a/docs/java/collection/priorityqueue-source-code.md +++ b/docs/java/collection/priorityqueue-source-code.md @@ -11,5 +11,4 @@ tag: - - \ No newline at end of file + diff --git a/docs/java/concurrent/aqs.md b/docs/java/concurrent/aqs.md index 0c8a63cc..acf080d9 100644 --- a/docs/java/concurrent/aqs.md +++ b/docs/java/concurrent/aqs.md @@ -791,4 +791,4 @@ threadnum:7is finish - Java 并发之 AQS 详解: - 从 ReentrantLock 的实现看 AQS 的原理及应用: - \ No newline at end of file + diff --git a/docs/java/concurrent/atomic-classes.md b/docs/java/concurrent/atomic-classes.md index cddffc95..ea759622 100644 --- a/docs/java/concurrent/atomic-classes.md +++ b/docs/java/concurrent/atomic-classes.md @@ -447,4 +447,4 @@ class User { - 《Java 并发编程的艺术》 - \ No newline at end of file + diff --git a/docs/java/concurrent/completablefuture-intro.md b/docs/java/concurrent/completablefuture-intro.md index cf3d8565..1b980bf4 100644 --- a/docs/java/concurrent/completablefuture-intro.md +++ b/docs/java/concurrent/completablefuture-intro.md @@ -715,6 +715,4 @@ CompletableFuture.runAsync(() -> { 另外,建议 G 友们可以看看京东的 [asyncTool](https://gitee.com/jd-platform-opensource/asyncTool) 这个并发框架,里面大量使用到了 `CompletableFuture` 。 - - - \ No newline at end of file + diff --git a/docs/java/concurrent/java-concurrent-collections.md b/docs/java/concurrent/java-concurrent-collections.md index cfe2d83f..4ae94eb9 100644 --- a/docs/java/concurrent/java-concurrent-collections.md +++ b/docs/java/concurrent/java-concurrent-collections.md @@ -152,4 +152,4 @@ private static ArrayBlockingQueue blockingQueue = new ArrayBlockingQueu - https://javadoop.com/post/java-concurrent-queue - https://juejin.im/post/5aeebd02518825672f19c546 - \ No newline at end of file + diff --git a/docs/java/concurrent/java-concurrent-questions-01.md b/docs/java/concurrent/java-concurrent-questions-01.md index d5fd6d11..3bf2d180 100644 --- a/docs/java/concurrent/java-concurrent-questions-01.md +++ b/docs/java/concurrent/java-concurrent-questions-01.md @@ -358,4 +358,4 @@ new 一个 `Thread`,线程进入了新建状态。调用 `start()`方法,会 **总结:调用 `start()` 方法方可启动线程并使线程进入就绪状态,直接执行 `run()` 方法的话不会以多线程的方式执行。** - \ No newline at end of file + diff --git a/docs/java/concurrent/java-thread-pool-best-practices.md b/docs/java/concurrent/java-thread-pool-best-practices.md index 61f7693b..12604ca1 100644 --- a/docs/java/concurrent/java-thread-pool-best-practices.md +++ b/docs/java/concurrent/java-thread-pool-best-practices.md @@ -297,4 +297,4 @@ server.tomcat.max-threads=1 `TransmittableThreadLocal` 项目地址:https://github.com/alibaba/transmittable-thread-local 。 - \ No newline at end of file + diff --git a/docs/java/concurrent/java-thread-pool-summary.md b/docs/java/concurrent/java-thread-pool-summary.md index d3c7aab4..e232aae9 100644 --- a/docs/java/concurrent/java-thread-pool-summary.md +++ b/docs/java/concurrent/java-thread-pool-summary.md @@ -811,4 +811,4 @@ public class ScheduledThreadPoolExecutor - [java.util.concurrent.ScheduledThreadPoolExecutor Example](https://examples.javacodegeeks.com/core-java/util/concurrent/scheduledthreadpoolexecutor/java-util-concurrent-scheduledthreadpoolexecutor-example/ "java.util.concurrent.ScheduledThreadPoolExecutor Example") - [ThreadPoolExecutor – Java Thread Pool Example](https://www.journaldev.com/1069/threadpoolexecutor-java-thread-pool-example-executorservice "ThreadPoolExecutor – Java Thread Pool Example") - \ No newline at end of file + diff --git a/docs/java/concurrent/jmm.md b/docs/java/concurrent/jmm.md index 9b93eaad..8cf977f7 100644 --- a/docs/java/concurrent/jmm.md +++ b/docs/java/concurrent/jmm.md @@ -237,4 +237,4 @@ happens-before 与 JMM 的关系用《Java 并发编程的艺术》这本书中 - 嘿,同学,你要的 Java 内存模型 (JMM) 来了:https://xie.infoq.cn/article/739920a92d0d27e2053174ef2 - JSR 133 (Java Memory Model) FAQ:https://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html - \ No newline at end of file + diff --git a/docs/java/concurrent/optimistic-lock-and-pessimistic-lock.md b/docs/java/concurrent/optimistic-lock-and-pessimistic-lock.md index eb523178..5b72ce2b 100644 --- a/docs/java/concurrent/optimistic-lock-and-pessimistic-lock.md +++ b/docs/java/concurrent/optimistic-lock-and-pessimistic-lock.md @@ -173,4 +173,4 @@ CAS 只对单个共享变量有效,当操作涉及跨多个共享变量时 CAS - 通俗易懂 悲观锁、乐观锁、可重入锁、自旋锁、偏向锁、轻量/重量级锁、读写锁、各种锁及其 Java 实现!:https://zhuanlan.zhihu.com/p/71156910 - 一文彻底搞懂 CAS 实现原理 & 深入到 CPU 指令:https://zhuanlan.zhihu.com/p/94976168 - \ No newline at end of file + diff --git a/docs/java/concurrent/reentrantlock.md b/docs/java/concurrent/reentrantlock.md index 5ed5acba..612739a0 100644 --- a/docs/java/concurrent/reentrantlock.md +++ b/docs/java/concurrent/reentrantlock.md @@ -1019,4 +1019,4 @@ public class LeeMain { - 《Java 并发编程实战》 - [不可不说的 Java“锁”事](https://tech.meituan.com/2018/11/15/java-lock.html) - \ No newline at end of file + diff --git a/docs/java/concurrent/threadlocal.md b/docs/java/concurrent/threadlocal.md index 37a4e785..93d8c4e6 100644 --- a/docs/java/concurrent/threadlocal.md +++ b/docs/java/concurrent/threadlocal.md @@ -911,4 +911,4 @@ public class MyThreadPoolTaskExecutor extends ThreadPoolTaskExecutor { 在 MQ 发送的消息体中自定义属性`requestId`,接收方消费消息后,自己解析`requestId`使用即可。 - \ No newline at end of file + diff --git a/docs/java/concurrent/virtual-thread.md b/docs/java/concurrent/virtual-thread.md index 7489828c..d5f6fe39 100644 --- a/docs/java/concurrent/virtual-thread.md +++ b/docs/java/concurrent/virtual-thread.md @@ -5,7 +5,7 @@ tag: - Java并发 --- -> 本文部分内容来自 [Lorin](https://github.com/Lorin-github) 的[PR](https://github.com/Snailclimb/JavaGuide/pull/2190)。 +> 本文部分内容来自 [Lorin](https://github.com/Lorin-github) 的[PR](https://github.com/Snailclimb/JavaGuide/pull/2190)。 虚拟线程在 Java 21 正式发布,这是一项重量级的更新。 @@ -26,11 +26,13 @@ tag: ## 虚拟线程有什么优点和缺点? ### 优点 + - 非常轻量级:可以在单个线程中创建成百上千个虚拟线程而不会导致过多的线程创建和上下文切换。 - 简化异步编程: 虚拟线程可以简化异步编程,使代码更易于理解和维护。它可以将异步代码编写得更像同步代码,避免了回调地狱(Callback Hell)。 - 减少资源开销: 相比于操作系统线程,虚拟线程的资源开销更小。本质上是提高了线程的执行效率,从而减少线程资源的创建和上下文切换。 ### 缺点 + - 不适用于计算密集型任务: 虚拟线程适用于 I/O 密集型任务,但不适用于计算密集型任务,因为密集型计算始终需要 CPU 资源作为支持。 - 依赖于语言或库的支持: 协程需要编程语言或库提供支持。不是所有编程语言都原生支持协程。比如 Java 实现的虚拟线程。 @@ -44,42 +46,41 @@ Java 21 已经正式支持虚拟线程,大家可以在官网下载使用,在 2. 使用 `Thread.ofVirtual()` 创建 3. 使用 `ThreadFactory` 创建 - #### 使用 Thread.startVirtualThread()创建 ```java -public class VirtualThreadTest { - public static void main(String[] args) { +public class VirtualThreadTest { + public static void main(String[] args) { CustomThread customThread = new CustomThread(); - Thread.startVirtualThread(customThread); + Thread.startVirtualThread(customThread); } } -static class CustomThread implements Runnable { - @Override - public void run() { - System.out.println("CustomThread run"); - } +static class CustomThread implements Runnable { + @Override + public void run() { + System.out.println("CustomThread run"); + } } ``` #### 使用 Thread.ofVirtual()创建 ```java -public class VirtualThreadTest { - public static void main(String[] args) { +public class VirtualThreadTest { + public static void main(String[] args) { CustomThread customThread = new CustomThread(); // 创建不启动 Thread unStarted = Thread.ofVirtual().unstarted(customThread); - unStarted.start(); + unStarted.start(); // 创建直接启动 - Thread.ofVirtual().start(customThread); + Thread.ofVirtual().start(customThread); } } -static class CustomThread implements Runnable { +static class CustomThread implements Runnable { @Override - public void run() { - System.out.println("CustomThread run"); + public void run() { + System.out.println("CustomThread run"); } } ``` @@ -87,12 +88,12 @@ static class CustomThread implements Runnable { #### 使用 ThreadFactory 创建 ```java -public class VirtualThreadTest { - public static void main(String[] args) { +public class VirtualThreadTest { + public static void main(String[] args) { CustomThread customThread = new CustomThread(); ThreadFactory factory = Thread.ofVirtual().factory(); Thread thread = factory.newThread(customThread); - thread.start(); + thread.start(); } } @@ -118,11 +119,12 @@ static class CustomThread implements Runnable { @Override public void run() { System.out.println("CustomThread run"); - } + } } ``` ## 虚拟线程和平台线程性能对比 + 通过多线程和虚拟线程的方式处理相同的任务,对比创建的系统线程数和处理耗时。 **说明**:统计创建的系统线程中部分为后台线程(比如 GC 线程),两种场景下都一样,所以并不影响对比。 @@ -227,4 +229,4 @@ totalMillis:2865ms - 因此,在密集 IO 的场景,虚拟线程可以大幅提高线程的执行效率,减少线程资源的创建以及上下文切换。 - 吐槽:虽然虚拟线程我很想用,但是我 Java8 有机会升级到 Java21 吗?呜呜 -**注意**:有段时间 JDK 一直致力于 Reactor 响应式编程来提高 Java 性能,但响应式编程难以理解、调试、使用,最终又回到了同步编程,最终虚拟线程诞生。 \ No newline at end of file +**注意**:有段时间 JDK 一直致力于 Reactor 响应式编程来提高 Java 性能,但响应式编程难以理解、调试、使用,最终又回到了同步编程,最终虚拟线程诞生。 diff --git a/docs/java/io/io-basis.md b/docs/java/io/io-basis.md index 048a560b..0dd36b1c 100755 --- a/docs/java/io/io-basis.md +++ b/docs/java/io/io-basis.md @@ -545,4 +545,4 @@ randomAccessFile.write(new byte[]{'H', 'I', 'J', 'K'}); `RandomAccessFile` 的实现依赖于 `FileDescriptor` (文件描述符) 和 `FileChannel` (内存映射文件)。 - \ No newline at end of file + diff --git a/docs/java/io/io-model.md b/docs/java/io/io-model.md index 8f7c0756..38251897 100644 --- a/docs/java/io/io-model.md +++ b/docs/java/io/io-model.md @@ -129,4 +129,4 @@ AIO 也就是 NIO 2。Java 7 中引入了 NIO 的改进版 NIO 2,它是异步 IO - IO 模型知多少 | 理论篇:https://www.cnblogs.com/sheng-jie/p/how-much-you-know-about-io-models.html - 《UNIX 网络编程 卷 1;套接字联网 API 》6.2 节 IO 模型 - \ No newline at end of file + diff --git a/docs/java/io/nio-basis.md b/docs/java/io/nio-basis.md index a3ccc686..8361b24f 100644 --- a/docs/java/io/nio-basis.md +++ b/docs/java/io/nio-basis.md @@ -6,7 +6,7 @@ tag: - Java基础 --- -在学习 NIO 之前,需要先了解一下计算机 I/O 模型的基础理论知识。还不了解的话,可以参考我写的这篇文章:[Java IO 模型详解](https://javaguide.cn/java/io/io-model.html)。 +在学习 NIO 之前,需要先了解一下计算机 I/O 模型的基础理论知识。还不了解的话,可以参考我写的这篇文章:[Java IO 模型详解](https://javaguide.cn/java/io/io-model.html)。 ## NIO 简介 @@ -48,7 +48,7 @@ NIO 主要包括以下三个核心组件: 为了更清晰地认识缓冲区,我们来简单看看`Buffer` 类中定义的四个成员变量: -~~~java +```java public abstract class Buffer { // Invariants: mark <= position <= limit <= capacity private int mark = -1; @@ -56,7 +56,7 @@ public abstract class Buffer { private int limit; private int capacity; } -~~~ +``` 这四个成员变量的具体含义如下: @@ -73,18 +73,18 @@ public abstract class Buffer { ![position 、limit 和 capacity 之前的关系](https://oss.javaguide.cn/github/javaguide/java/nio/NIOBufferClassAttributes.png) - `Buffer` 对象不能通过 `new` 调用构造方法创建对象 ,只能通过静态方法实例化 `Buffer`。 +`Buffer` 对象不能通过 `new` 调用构造方法创建对象 ,只能通过静态方法实例化 `Buffer`。 这里以 `ByteBuffer`为例进行介绍: -~~~java +```java // 分配堆内存 -public static ByteBuffer allocate(int capacity); +public static ByteBuffer allocate(int capacity); // 分配直接内存 -public static ByteBuffer allocateDirect(int capacity); -~~~ +public static ByteBuffer allocateDirect(int capacity); +``` - Buffer 最核心的两个方法: +Buffer 最核心的两个方法: 1. `get` : 读取缓冲区的数据 2. `put` :向缓冲区写入数据 @@ -92,20 +92,20 @@ public static ByteBuffer allocateDirect(int capacity); 除上述两个方法之外,其他的重要方法: - `flip` :将缓冲区从写模式切换到读模式,它会将 `limit` 的值设置为当前 `position` 的值,将 `position` 的值设置为 0。 -- `clear`: 清空缓冲区,将缓冲区从读模式切换到写模式,并将 `position` 的值设置为 0,将 `limit` 的值设置为 `capacity` 的值。 +- `clear`: 清空缓冲区,将缓冲区从读模式切换到写模式,并将 `position` 的值设置为 0,将 `limit` 的值设置为 `capacity` 的值。 - …… Buffer 中数据变化的过程: -~~~java +```java import java.nio.*; public class CharBufferDemo { public static void main(String[] args) { // 分配一个容量为8的CharBuffer CharBuffer buffer = CharBuffer.allocate(8); - System.out.println("初始状态:"); - printState(buffer); + System.out.println("初始状态:"); + printState(buffer); // 向buffer写入3个字符 buffer.put('a').put('b').put('c'); @@ -118,7 +118,7 @@ public class CharBufferDemo { printState(buffer); // 读取字符 - while (buffer.hasRemaining()) { + while (buffer.hasRemaining()) { System.out.print(buffer.get()); } @@ -138,11 +138,11 @@ public class CharBufferDemo { System.out.println("\n"); } } -~~~ +``` 输出: -~~~bash +```bash 初始状态: capacity: 8, limit: 8, position: 0 @@ -157,8 +157,8 @@ capacity: 8, limit: 3, position: 0 读取到的数据:abc 调用clear()方法后的状态: -capacity: 8, limit: 8, position: 0 -~~~ +capacity: 8, limit: 8, position: 0 +``` 为了帮助理解,我绘制了一张图片展示 `capacity`、`limit`和`position`每一阶段的变化。 @@ -188,20 +188,19 @@ Channel 与前面介绍的 Buffer 打交道,读操作的时候将 Channel 中 ![Channel继承关系图](https://oss.javaguide.cn/github/javaguide/java/nio/channel-inheritance-relationship.png) - - Channel 最核心的两个方法: +Channel 最核心的两个方法: 1. `read` :读取数据并写入到 Buffer 中。 2. `write` :将 Buffer 中的数据写入到 Channel 中。 这里我们以 `FileChannel` 为例演示一下是读取文件数据的。 -~~~java -RandomAccessFile reader = new RandomAccessFile("/Users/guide/Documents/test_read.in", "r")) +```java +RandomAccessFile reader = new RandomAccessFile("/Users/guide/Documents/test_read.in", "r")) FileChannel channel = reader.getChannel(); ByteBuffer buffer = ByteBuffer.allocate(1024); channel.read(buffer); -~~~ +``` ### Selector(选择器) @@ -252,13 +251,13 @@ Selector 还提供了一系列和 `select()` 相关的方法: - `int select()`:监控所有注册的 `Channel`,当它们中间有需要处理的 `IO` 操作时,该方法返回,并将对应的 `SelectionKey` 加入被选择的 `SelectionKey` 集合中,该方法返回这些 `Channel` 的数量。 - `int select(long timeout)`:可以设置超时时长的 `select()` 操作。 -- `int selectNow()`:执行一个立即返回的 `select()` 操作,相对于无参数的 `select()` 方法而言,该方法不会阻塞线程。 +- `int selectNow()`:执行一个立即返回的 `select()` 操作,相对于无参数的 `select()` 方法而言,该方法不会阻塞线程。 - `Selector wakeup()`:使一个还未返回的 `select()` 方法立刻返回。 - …… 使用 Selector 实现网络读写的简单示例: -~~~java +```java import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; @@ -335,7 +334,7 @@ public class NioSelectorExample { } } } -~~~ +``` 在示例中,我们创建了一个简单的服务器,监听 8080 端口,使用 Selector 处理连接、读取和写入事件。当接收到客户端的数据时,服务器将读取数据并将其打印到控制台,然后向客户端回复 "Hello, Client!"。 @@ -390,5 +389,4 @@ private void loadFileIntoMemory(File xmlFile) throws IOException { - Java NIO:Buffer、Channel 和 Selector:https://www.javadoop.com/post/java-nio - - \ No newline at end of file + diff --git a/docs/java/jvm/class-file-structure.md b/docs/java/jvm/class-file-structure.md index 2faf3452..a9c8aae2 100644 --- a/docs/java/jvm/class-file-structure.md +++ b/docs/java/jvm/class-file-structure.md @@ -97,11 +97,11 @@ ClassFile { | CONSTANT_utf8_info | 1 | UTF-8 编码的字符串 | | CONSTANT_Integer_info | 3 | 整形字面量 | | CONSTANT_Float_info | 4 | 浮点型字面量 | -| CONSTANT_Long_info | 5 | 长整型字面量 | -| CONSTANT_Double_info | 6 | 双精度浮点型字面量 | -| CONSTANT_Class_info | 7 | 类或接口的符号引用 | -| CONSTANT_String_info | 8 | 字符串类型字面量 | -| CONSTANT_FieldRef_info | 9 | 字段的符号引用 | +| CONSTANT_Long_info | 5 | 长整型字面量 | +| CONSTANT_Double_info | 6 | 双精度浮点型字面量 | +| CONSTANT_Class_info | 7 | 类或接口的符号引用 | +| CONSTANT_String_info | 8 | 字符串类型字面量 | +| CONSTANT_FieldRef_info | 9 | 字段的符号引用 | | CONSTANT_MethodRef_info | 10 | 类中方法的符号引用 | | CONSTANT_InterfaceMethodRef_info | 11 | 接口中方法的符号引用 | | CONSTANT_NameAndType_info | 12 | 字段或方法的符号引用 | @@ -213,4 +213,4 @@ Class 文件存储格式中对方法的描述与对字段的描述几乎采用 - 实例分析 JAVA CLASS 的文件结构: - 《Java 虚拟机原理图解》 1.2.2、Class 文件中的常量池详解(上): - \ No newline at end of file + diff --git a/docs/java/jvm/class-loading-process.md b/docs/java/jvm/class-loading-process.md index a98d3994..1ca7e5ab 100644 --- a/docs/java/jvm/class-loading-process.md +++ b/docs/java/jvm/class-loading-process.md @@ -143,4 +143,4 @@ tag: - 《实战 Java 虚拟机》 - Chapter 5. Loading, Linking, and Initializing - Java Virtual Machine Specification:https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html#jvms-5.4 - \ No newline at end of file + diff --git a/docs/java/jvm/classloader.md b/docs/java/jvm/classloader.md index a4259e77..ad249881 100644 --- a/docs/java/jvm/classloader.md +++ b/docs/java/jvm/classloader.md @@ -347,4 +347,4 @@ cl = Thread.currentThread().getContextClassLoader(); - Class ClassLoader - Oracle 官方文档:https://docs.oracle.com/javase/8/docs/api/java/lang/ClassLoader.html - 老大难的 Java ClassLoader 再不理解就老了:https://zhuanlan.zhihu.com/p/51374915 - \ No newline at end of file + diff --git a/docs/java/jvm/jdk-monitoring-and-troubleshooting-tools.md b/docs/java/jvm/jdk-monitoring-and-troubleshooting-tools.md index 179df728..8c3acfb3 100644 --- a/docs/java/jvm/jdk-monitoring-and-troubleshooting-tools.md +++ b/docs/java/jvm/jdk-monitoring-and-troubleshooting-tools.md @@ -309,4 +309,4 @@ VisualVM 基于 NetBeans 平台开发,因此他一开始就具备了插件扩 - - - \ No newline at end of file + diff --git a/docs/java/jvm/jvm-garbage-collection.md b/docs/java/jvm/jvm-garbage-collection.md index c8495c09..b526c30d 100644 --- a/docs/java/jvm/jvm-garbage-collection.md +++ b/docs/java/jvm/jvm-garbage-collection.md @@ -57,10 +57,10 @@ Java 堆是垃圾收集器管理的主要区域,因此也被称作 **GC 堆( ```java public class GCTest { - public static void main(String[] args) { - byte[] allocation1, allocation2; - allocation1 = new byte[30900*1024]; - } + public static void main(String[] args) { + byte[] allocation1, allocation2; + allocation1 = new byte[30900*1024]; + } } ``` @@ -91,14 +91,14 @@ allocation2 = new byte[900*1024]; ```java public class GCTest { - public static void main(String[] args) { - byte[] allocation1, allocation2,allocation3,allocation4,allocation5; - allocation1 = new byte[32000*1024]; - allocation2 = new byte[1000*1024]; - allocation3 = new byte[1000*1024]; - allocation4 = new byte[1000*1024]; - allocation5 = new byte[1000*1024]; - } + public static void main(String[] args) { + byte[] allocation1, allocation2,allocation3,allocation4,allocation5; + allocation1 = new byte[32000*1024]; + allocation2 = new byte[1000*1024]; + allocation3 = new byte[1000*1024]; + allocation4 = new byte[1000*1024]; + allocation5 = new byte[1000*1024]; + } } ``` @@ -109,8 +109,8 @@ public class GCTest { 大对象直接进入老年代的行为是由虚拟机动态决定的,它与具体使用的垃圾回收器和相关参数有关。大对象直接进入老年代是一种优化策略,旨在避免将大对象放入新生代,从而减少新生代的垃圾回收频率和成本。 -* G1 垃圾回收器会根据-XX:G1HeapRegionSize参数设置的堆区域大小和-XX:G1MixedGCLiveThresholdPercent参数设置的阈值,来决定哪些对象会直接进入老年代。 -* Parallel Scavenge 垃圾回收器中,默认情况下,并没有一个固定的阈值(XX:ThresholdTolerance是动态调整的)来决定何时直接在老年代分配大对象。而是由虚拟机根据当前的堆内存情况和历史数据动态决定。 +- G1 垃圾回收器会根据 `-XX:G1HeapRegionSize` 参数设置的堆区域大小和 `-XX:G1MixedGCLiveThresholdPercent` 参数设置的阈值,来决定哪些对象会直接进入老年代。 +- Parallel Scavenge 垃圾回收器中,默认情况下,并没有一个固定的阈值(`XX:ThresholdTolerance`是动态调整的)来决定何时直接在老年代分配大对象。而是由虚拟机根据当前的堆内存情况和历史数据动态决定。 ### 长期存活的对象将进入老年代 @@ -122,7 +122,7 @@ public class GCTest { > 修正([issue552](https://github.com/Snailclimb/JavaGuide/issues/552)):“Hotspot 遍历所有对象时,按照年龄从小到大对其所占用的大小进行累积,当累积的某个年龄大小超过了 survivor 区的 50% 时(默认值是 50%,可以通过 `-XX:TargetSurvivorRatio=percent` 来设置,参见 [issue1199](https://github.com/Snailclimb/JavaGuide/issues/1199) ),取这个年龄和 MaxTenuringThreshold 中更小的一个值,作为新的晋升年龄阈值”。 > -> jdk8 官方文档引用:https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html 。 +> jdk8 官方文档引用:。 > > ![](https://oss.javaguide.cn/java-guide-blog/image-20210523201742303.png) > @@ -234,7 +234,6 @@ public class ReferenceCountingGc { - 所有被同步锁持有的对象 - JNI(Java Native Interface)引用的对象 - **对象可以被回收,就代表一定会被回收吗?** 即使在可达性分析法中不可达的对象,也并非是“非死不可”的,这时候它们暂时处于“缓刑阶段”,要真正宣告一个对象死亡,至少要经历两次标记过程;可达性分析法中不可达的对象被第一次标记并且进行一次筛选,筛选的条件是此对象是否有必要执行 `finalize` 方法。当对象没有覆盖 `finalize` 方法,或 `finalize` 方法已经被虚拟机调用过时,虚拟机将这两种情况视为没有必要执行。 diff --git a/docs/java/jvm/jvm-in-action.md b/docs/java/jvm/jvm-in-action.md index 0bf90f3f..8f6d00ad 100644 --- a/docs/java/jvm/jvm-in-action.md +++ b/docs/java/jvm/jvm-in-action.md @@ -52,4 +52,4 @@ JVM 线上问题排查和性能调优也是面试常问的一个问题,尤其 这篇文章共 2w+ 字,详细介绍了 GC 基础,总结了 CMS GC 的一些常见问题分析与解决办法。 - \ No newline at end of file + diff --git a/docs/java/jvm/jvm-intro.md b/docs/java/jvm/jvm-intro.md index 5d0880bb..dbf56ba1 100644 --- a/docs/java/jvm/jvm-intro.md +++ b/docs/java/jvm/jvm-intro.md @@ -530,4 +530,4 @@ JDK5.0 以后每个线程堆栈大小为 1M,以前每个线程堆栈大小为 真的扯了很久这东西,参考了多方的资料,有极客时间的《深入拆解虚拟机》和《Java 核心技术面试精讲》,也有百度,也有自己在学习的一些线上课程的总结。希望对你有所帮助,谢谢。 - \ No newline at end of file + diff --git a/docs/java/jvm/jvm-parameters-intro.md b/docs/java/jvm/jvm-parameters-intro.md index 39d595fb..eb533a03 100644 --- a/docs/java/jvm/jvm-parameters-intro.md +++ b/docs/java/jvm/jvm-parameters-intro.md @@ -232,4 +232,4 @@ JVM 具有四种类型的 GC 实现: - [Java 中 9 种常见的 CMS GC 问题分析与解决 - 美团技术团队 - 2020](https://tech.meituan.com/2020/11/12/java-9-cms-gc.html) - [从实际案例聊聊 Java 应用的 GC 优化-美团技术团队 - 美团技术团队 - 2017](https://tech.meituan.com/2017/12/29/jvm-optimize.html) - \ No newline at end of file + diff --git a/docs/java/jvm/memory-area.md b/docs/java/jvm/memory-area.md index fc35b606..09df3ceb 100644 --- a/docs/java/jvm/memory-area.md +++ b/docs/java/jvm/memory-area.md @@ -352,4 +352,4 @@ HotSpot 虚拟机主要使用的就是这种方式来进行对象访问。 - - - \ No newline at end of file + diff --git a/docs/java/new-features/java10.md b/docs/java/new-features/java10.md index 7fffdc52..fa137528 100644 --- a/docs/java/new-features/java10.md +++ b/docs/java/new-features/java10.md @@ -116,4 +116,4 @@ Oracle 的 HotSpot VM 便附带两个用 C++ 实现的 JIT compiler:C1 及 C2 - 4 Class Data Sharing : https://docs.oracle.com/javase/10/vm/class-data-sharing.htm#JSJVM-GUID-7EAA3411-8CF0-4D19-BD05-DF5E1780AA91 - \ No newline at end of file + diff --git a/docs/java/new-features/java11.md b/docs/java/new-features/java11.md index 54de2234..599a2ad0 100644 --- a/docs/java/new-features/java11.md +++ b/docs/java/new-features/java11.md @@ -128,4 +128,4 @@ Consumer consumer = (String i) -> System.out.println(i); - JDK 11 Release Notes:https://www.oracle.com/java/technologies/javase/11-relnote-issues.html - Java 11 – Features and Comparison: - \ No newline at end of file + diff --git a/docs/java/new-features/java12-13.md b/docs/java/new-features/java12-13.md index 225aa996..265a3d0a 100644 --- a/docs/java/new-features/java12-13.md +++ b/docs/java/new-features/java12-13.md @@ -295,4 +295,4 @@ public String translateEscapes() { - New Java13 Features - Java13 新特性概述 - \ No newline at end of file + diff --git a/docs/java/new-features/java14-15.md b/docs/java/new-features/java14-15.md index 80da94fa..f84913e4 100644 --- a/docs/java/new-features/java14-15.md +++ b/docs/java/new-features/java14-15.md @@ -240,4 +240,4 @@ Java 15 并没有对此特性进行调整,继续预览特性,主要用于接 - **禁用和废弃偏向锁(Biased Locking)**:偏向锁的引入增加了 JVM 的复杂性大于其带来的性能提升。不过,你仍然可以使用 `-XX:+UseBiasedLocking` 启用偏向锁定,但它会提示 这是一个已弃用的 API。 - …… - \ No newline at end of file + diff --git a/docs/java/new-features/java16.md b/docs/java/new-features/java16.md index e38d076e..25cb308d 100644 --- a/docs/java/new-features/java16.md +++ b/docs/java/new-features/java16.md @@ -149,4 +149,4 @@ public class Outer { - [Java 16 正式发布,新特性一一解析](https://www.infoq.cn/article/IAkwhx7i9V7G8zLVEd4L) - [实操 | 剖析 Java16 新语法特性](https://xie.infoq.cn/article/8304c894c4e38318d38ceb116)(写的很赞) - \ No newline at end of file + diff --git a/docs/java/new-features/java17.md b/docs/java/new-features/java17.md index 49931bc0..e478f1f5 100644 --- a/docs/java/new-features/java17.md +++ b/docs/java/new-features/java17.md @@ -173,4 +173,4 @@ Java 程序可以通过该 API 与 Java 运行时之外的代码和数据进行 在 [Java 18 新特性概览](./java18.md) 中,我有详细介绍到向量 API,这里就不再做额外的介绍了。 - \ No newline at end of file + diff --git a/docs/java/new-features/java18.md b/docs/java/new-features/java18.md index a7d585da..40fa7bb6 100644 --- a/docs/java/new-features/java18.md +++ b/docs/java/new-features/java18.md @@ -138,4 +138,4 @@ Java 程序可以通过该 API 与 Java 运行时之外的代码和数据进行 在 [Java 19 新特性概览](./java19.md) 中,我有详细介绍到外部函数和内存 API,这里就不再做额外的介绍了。 - \ No newline at end of file + diff --git a/docs/java/new-features/java19.md b/docs/java/new-features/java19.md index 5fd1c744..3e9a931e 100644 --- a/docs/java/new-features/java19.md +++ b/docs/java/new-features/java19.md @@ -115,4 +115,4 @@ JDK 19 引入了结构化并发,一种多线程编程方法,目的是为了 结构化并发非常适合虚拟线程,虚拟线程是 JDK 实现的轻量级线程。许多虚拟线程共享同一个操作系统线程,从而允许非常多的虚拟线程。 - \ No newline at end of file + diff --git a/docs/java/new-features/java20.md b/docs/java/new-features/java20.md index f78ce8c3..38da39d9 100644 --- a/docs/java/new-features/java20.md +++ b/docs/java/new-features/java20.md @@ -268,7 +268,7 @@ ThreadFactory factory = Thread.ofVirtual().factory(); // 创建虚拟线程 Thread thread = factory.newThread(customThread); // 启动线程 -thread.start(); +thread.start(); ``` 通过上述列举的 4 种创建虚拟线程的方式可以看出,官方为了降低虚拟线程的门槛,尽力复用原有的 `Thread` 线程类,这样可以平滑的过渡到虚拟线程的使用。 @@ -309,4 +309,4 @@ JDK 20 中对结构化并发唯一变化是更新为支持在任务范围内创 Java20 的这次孵化基本没有改变向量 API ,只是进行了一些错误修复和性能增强,详见 [JEP 438](https://openjdk.org/jeps/438)。 - \ No newline at end of file + diff --git a/docs/java/new-features/java21.md b/docs/java/new-features/java21.md index 0db58c38..fa6c371d 100644 --- a/docs/java/new-features/java21.md +++ b/docs/java/new-features/java21.md @@ -22,7 +22,7 @@ JDK 21 共有 15 个新特性: ## JEP 430:字符串模板(预览) -String Templates(字符串模板) 目前仍然是 JDK 21 中的一个预览功能。 +String Templates(字符串模板) 目前仍然是 JDK 21 中的一个预览功能。 String Templates 提供了一种更简洁、更直观的方式来动态构建字符串。通过使用占位符`${}`,我们可以将变量的值直接嵌入到字符串中,而不需要手动处理。在运行时,Java 编译器会将这些占位符替换为实际的变量值。并且,表达式支持局部变量、静态/非静态字段甚至方法、计算结果等特性。 @@ -39,7 +39,7 @@ Java 在没有 String Templates 之前,我们通常使用字符串拼接或格 ```java //concatenation -message = "Greetings " + name + "!"; +message = "Greetings " + name + "!"; //String.format() message = String.format("Greetings %s!", name); //concatenation @@ -53,7 +53,7 @@ message = new StringBuilder().append("Greetings ").append(name).append("!").toSt 这些方法或多或少都存在一些缺点,比如难以阅读、冗长、复杂。 -Java 使用 String Templates 进行字符串拼接,可以直接在字符串中嵌入表达式,而无需进行额外的处理: +Java 使用 String Templates 进行字符串拼接,可以直接在字符串中嵌入表达式,而无需进行额外的处理: ```java String message = STR."Greetings \{name}!"; @@ -71,7 +71,7 @@ String message = STR."Greetings \{name}!"; - RAW:不会像 STR 和 FMT 模板处理器那样自动处理字符串模板,而是返回一个 `StringTemplate` 对象,这个对象包含了模板中的文本和表达式的信息 ```java -String name = "Lokesh"; +String name = "Lokesh"; //STR String message = STR."Greetings \{name}."; @@ -155,4 +155,3 @@ java -XX:+UseZGC -XX:+ZGenerational ... ## 参考 - Java 21 String Templates: - diff --git a/docs/java/new-features/java8-common-new-features.md b/docs/java/new-features/java8-common-new-features.md index 427cccbd..a7bfc05a 100644 --- a/docs/java/new-features/java8-common-new-features.md +++ b/docs/java/new-features/java8-common-new-features.md @@ -1053,4 +1053,4 @@ System.out.println("本地时区时间: " + localZoned); 这些都是开发当中比较常用的特性。梳理下来发现它们真香,而我却没有更早的应用。总觉得学习 java 8 新特性比较麻烦,一直使用老的实现方式。其实这些新特性几天就可以掌握,一但掌握,效率会有很大的提高。其实我们涨工资也是涨的学习的钱,不学习终究会被淘汰,35 岁危机会提前来临。 - \ No newline at end of file + diff --git a/docs/java/new-features/java8-tutorial-translate.md b/docs/java/new-features/java8-tutorial-translate.md index 288cbd53..faabdd95 100644 --- a/docs/java/new-features/java8-tutorial-translate.md +++ b/docs/java/new-features/java8-tutorial-translate.md @@ -896,4 +896,4 @@ System.out.println(hints2.length); // 2 关于 Java 8 的新特性就写到这了,肯定还有更多的特性等待发掘。JDK 1.8 里还有很多很有用的东西,比如`Arrays.parallelSort`, `StampedLock`和`CompletableFuture`等等。 - \ No newline at end of file + diff --git a/docs/javaguide/use-suggestion.md b/docs/javaguide/use-suggestion.md index b56a085f..e7ce843a 100644 --- a/docs/javaguide/use-suggestion.md +++ b/docs/javaguide/use-suggestion.md @@ -24,4 +24,4 @@ icon: star 另外,记录博客或者用自己的理解把对应的知识点讲给别人听也是一个不错的选择。 -最后,准备技术面试的同学一定要定期复习(自测的方式非常好),不然确实会遗忘的。 \ No newline at end of file +最后,准备技术面试的同学一定要定期复习(自测的方式非常好),不然确实会遗忘的。 diff --git a/docs/open-source-project/tools.md b/docs/open-source-project/tools.md index ae48e143..90684495 100644 --- a/docs/open-source-project/tools.md +++ b/docs/open-source-project/tools.md @@ -53,6 +53,7 @@ icon: tool - [zktools](https://zktools.readthedocs.io/en/latest/#installing):一个低延迟的 ZooKeeper 图形化管理客户端,颜值非常高,支持 Mac / Windows / Linux 。你可以使用 zktools 来实现对 ZooKeeper 的可视化增删改查。 ## Kafka + - [Kafka UI](https://github.com/provectus/kafka-ui):免费的开源 Web UI,用于监控和管理 Apache Kafka 集群。 - [Kafdrop](https://github.com/obsidiandynamics/kafdrop) : 一个用于查看 Kafka 主题和浏览消费者组的 Web UI。 -- [EFAK](https://github.com/smartloli/EFAK) (Eagle For Apache Kafka,以前叫做 Kafka Eagle):一个简单的高性能监控系统,用于对 Kafka 集群进行全面的监控和管理。 \ No newline at end of file +- [EFAK](https://github.com/smartloli/EFAK) (Eagle For Apache Kafka,以前叫做 Kafka Eagle):一个简单的高性能监控系统,用于对 Kafka 集群进行全面的监控和管理。 diff --git a/docs/snippets/article-footer.snippet.md b/docs/snippets/article-footer.snippet.md index 88f9096a..5ec368ca 100644 --- a/docs/snippets/article-footer.snippet.md +++ b/docs/snippets/article-footer.snippet.md @@ -1,2 +1 @@ ![JavaGuide 官方公众号](https://oss.javaguide.cn/github/javaguide/gongzhonghaoxuanchuan.png) - diff --git a/docs/snippets/article-header.snippet.md b/docs/snippets/article-header.snippet.md index 0ddfde47..1bac94f1 100644 --- a/docs/snippets/article-header.snippet.md +++ b/docs/snippets/article-header.snippet.md @@ -1 +1 @@ -[![JavaGuide官方知识星球](https://oss.javaguide.cn/xingqiu/xingqiu.png)](../about-the-author/zhishixingqiu-two-years.md) \ No newline at end of file +[![JavaGuide官方知识星球](https://oss.javaguide.cn/xingqiu/xingqiu.png)](../about-the-author/zhishixingqiu-two-years.md) diff --git a/docs/snippets/planet2.snippet.md b/docs/snippets/planet2.snippet.md index 18732b67..cbd5df1c 100644 --- a/docs/snippets/planet2.snippet.md +++ b/docs/snippets/planet2.snippet.md @@ -1,11 +1,9 @@ ## 星球其他资源 -[知识星球](../about-the-author/zhishixingqiu-two-years.md)除了提供了 **《Java 面试指北》** 、 **《Java 必读源码系列》**(目前已经整理了 Dubbo 2.6.x 、Netty 4.x、SpringBoot2.1 的源码)、 **《手写 RPC 框架》** 、**《Kafka 常见面试题/知识点总结》** 等多个专属小册,还有 读书活动、学习打卡、简历修改、免费提问、海量 Java 优质面试资源以及各种不定时的福利。 +[知识星球](../about-the-author/zhishixingqiu-two-years.md)除了提供了 **《Java 面试指北》** 、 **《Java 必读源码系列》**(目前已经整理了 Dubbo 2.6.x 、Netty 4.x、SpringBoot2.1 的源码)、 **《手写 RPC 框架》** 、**《Kafka 常见面试题/知识点总结》** 等多个专属小册,还有 读书活动、学习打卡、简历修改、免费提问、海量 Java 优质面试资源以及各种不定时的福利。 ![知识星球专栏概览](https://oss.javaguide.cn/xingqiu/image-20220211231206733.png) - - ![星球 PDF 面试手册](https://oss.javaguide.cn/xingqiu/image-20220723120918434.png) 下面是星球提供的部分服务(点击下方图片即可获取知识星球的详细介绍): @@ -28,4 +26,4 @@ **无任何套路,无任何潜在收费项。用心做内容,不割韭菜!** -不过, **一定要确定需要再进** 。并且, **三天之内觉得内容不满意可以全额退款** 。 \ No newline at end of file +不过, **一定要确定需要再进** 。并且, **三天之内觉得内容不满意可以全额退款** 。 diff --git a/docs/snippets/yuanma.snippet.md b/docs/snippets/yuanma.snippet.md index 2df3b7ca..06daa2f4 100644 --- a/docs/snippets/yuanma.snippet.md +++ b/docs/snippets/yuanma.snippet.md @@ -25,4 +25,3 @@ **无任何套路,无任何潜在收费项。用心做内容,不割韭菜!** 不过, **一定要确定需要再进** 。并且, **三天之内觉得内容不满意可以全额退款** 。 - diff --git a/docs/system-design/J2EE基础知识.md b/docs/system-design/J2EE基础知识.md index b834abfc..f0d0b135 100644 --- a/docs/system-design/J2EE基础知识.md +++ b/docs/system-design/J2EE基础知识.md @@ -289,4 +289,4 @@ Cookie 数据保存在客户端(浏览器端),Session 数据保存在服务器 Cookie 存储在客户端中,而 Session 存储在服务器上,相对来说 Session 安全性更高。如果使用 Cookie 的一些敏感信息不要写入 Cookie 中,最好能将 Cookie 信息加密然后使用到的时候再去服务器端解密。 - \ No newline at end of file + diff --git a/docs/system-design/basis/RESTfulAPI.md b/docs/system-design/basis/RESTfulAPI.md index ed24bdd6..15671201 100644 --- a/docs/system-design/basis/RESTfulAPI.md +++ b/docs/system-design/basis/RESTfulAPI.md @@ -176,4 +176,4 @@ GET /classes?page=1&size=10 //指定第1页,每页10个数据 - - \ No newline at end of file + diff --git a/docs/system-design/basis/naming.md b/docs/system-design/basis/naming.md index 2b7ea718..4be3d038 100644 --- a/docs/system-design/basis/naming.md +++ b/docs/system-design/basis/naming.md @@ -248,4 +248,4 @@ Codelf 提供了在线网站版本,网址:[https://unbug.github.io/codelf/]( 最后,祝愿大家都不用再为命名而困扰! - \ No newline at end of file + diff --git a/docs/system-design/basis/refactoring.md b/docs/system-design/basis/refactoring.md index 72f5af3d..15b1b95f 100644 --- a/docs/system-design/basis/refactoring.md +++ b/docs/system-design/basis/refactoring.md @@ -141,4 +141,4 @@ Code Review 可以非常有效提高代码的整体质量,它会帮助我们 - [再读《重构》- ThoughtWorks 洞见 - 2020](https://insights.thoughtworks.cn/reread-refactoring/):详细介绍了重构的要点比如小步重构、捡垃圾式的重构,主要是重构概念相关的介绍。 - [常见代码重构技巧 - VectorJin - 2021](https://juejin.cn/post/6954378167947624484):从软件设计原则、设计模式、代码分层、命名规范等角度介绍了如何进行重构,比较偏实战。 - \ No newline at end of file + diff --git a/docs/system-design/basis/software-engineering.md b/docs/system-design/basis/software-engineering.md index 22c70854..c6cd4fa3 100644 --- a/docs/system-design/basis/software-engineering.md +++ b/docs/system-design/basis/software-engineering.md @@ -97,4 +97,4 @@ Dijkstra(Dijkstra 算法的作者) 在 1972 年图灵奖获奖感言中也 - 软件工程的基本概念-清华大学软件学院 刘强: - 软件开发过程-维基百科:[https://zh.wikipedia.org/wiki/软件开发过程](https://zh.wikipedia.org/wiki/软件开发过程) - \ No newline at end of file + diff --git a/docs/system-design/basis/unit-test.md b/docs/system-design/basis/unit-test.md index 689f30fa..ce969c93 100644 --- a/docs/system-design/basis/unit-test.md +++ b/docs/system-design/basis/unit-test.md @@ -135,4 +135,4 @@ Mockito 和 Spock 都是非常不错的 Mock 工具,相对来说,Mockito 的 **多敲代码实践,多跟有单元测试经验的工程师交流**,你会发现写单元测试获得的收益会更多。 - \ No newline at end of file + diff --git a/docs/system-design/design-pattern.md b/docs/system-design/design-pattern.md index 30fdbe91..2b9541f8 100644 --- a/docs/system-design/design-pattern.md +++ b/docs/system-design/design-pattern.md @@ -19,4 +19,4 @@ head: ![《设计模式》PDF文档概览](https://oss.javaguide.cn/github/javaguide/system-design/design-pattern-pdf.png) - \ No newline at end of file + diff --git a/docs/system-design/framework/mybatis/mybatis-interview.md b/docs/system-design/framework/mybatis/mybatis-interview.md index b12f7825..45f69255 100644 --- a/docs/system-design/framework/mybatis/mybatis-interview.md +++ b/docs/system-design/framework/mybatis/mybatis-interview.md @@ -308,4 +308,4 @@ MyBatis 提供了 9 种动态 sql 标签: - [从零开始实现一个 MyBatis 加解密插件](https://mp.weixin.qq.com/s/WUEAdFDwZsZ4EKO8ix0ijg) - [MyBatis 最全使用指南](https://juejin.cn/post/7051910683264286750) - [脑洞打开!第一次看到这样使用 MyBatis 的,看得我一愣一愣的。](https://juejin.cn/post/7269390456530190376) -- [MyBatis 居然也有并发问题](https://juejin.cn/post/7264921613551730722) \ No newline at end of file +- [MyBatis 居然也有并发问题](https://juejin.cn/post/7264921613551730722) diff --git a/docs/system-design/framework/netty.md b/docs/system-design/framework/netty.md index 8ece6e9f..1a0833f8 100644 --- a/docs/system-design/framework/netty.md +++ b/docs/system-design/framework/netty.md @@ -8,4 +8,4 @@ icon: "network" - \ No newline at end of file + diff --git a/docs/system-design/framework/spring/spring-boot-auto-assembly-principles.md b/docs/system-design/framework/spring/spring-boot-auto-assembly-principles.md index 698ebda1..8884085f 100644 --- a/docs/system-design/framework/spring/spring-boot-auto-assembly-principles.md +++ b/docs/system-design/framework/spring/spring-boot-auto-assembly-principles.md @@ -321,4 +321,4 @@ public class RabbitAutoConfiguration { Spring Boot 通过`@EnableAutoConfiguration`开启自动装配,通过 SpringFactoriesLoader 最终加载`META-INF/spring.factories`中的自动配置类实现自动装配,自动配置类其实就是通过`@Conditional`按需加载的配置类,想要其生效必须引入`spring-boot-starter-xxx`包实现起步依赖 - \ No newline at end of file + diff --git a/docs/system-design/framework/spring/spring-common-annotations.md b/docs/system-design/framework/spring/spring-common-annotations.md index 6e14df44..04dc411c 100644 --- a/docs/system-design/framework/spring/spring-common-annotations.md +++ b/docs/system-design/framework/spring/spring-common-annotations.md @@ -959,4 +959,4 @@ _暂时总结到这里吧!虽然花了挺长时间才写完,不过可能还 本文已经收录进我的 75K Star 的 Java 开源项目 JavaGuide:[https://github.com/Snailclimb/JavaGuide](https://github.com/Snailclimb/JavaGuide)。 - \ No newline at end of file + diff --git a/docs/system-design/framework/spring/spring-design-patterns-summary.md b/docs/system-design/framework/spring/spring-design-patterns-summary.md index ad0a0df0..a04ec1ef 100644 --- a/docs/system-design/framework/spring/spring-design-patterns-summary.md +++ b/docs/system-design/framework/spring/spring-design-patterns-summary.md @@ -352,4 +352,4 @@ Spring 框架中用到了哪些设计模式? - - - \ No newline at end of file + diff --git a/docs/system-design/framework/spring/spring-knowledge-and-questions-summary.md b/docs/system-design/framework/spring/spring-knowledge-and-questions-summary.md index 86240331..686739e4 100644 --- a/docs/system-design/framework/spring/spring-knowledge-and-questions-summary.md +++ b/docs/system-design/framework/spring/spring-knowledge-and-questions-summary.md @@ -129,7 +129,7 @@ Spring Boot 只是简化了配置,如果你需要构建 MVC 架构的 Web 程 Spring 时代我们一般通过 XML 文件来配置 Bean,后来开发人员觉得 XML 文件来配置不太好,于是 SpringBoot 注解配置就慢慢开始流行起来。 -相关阅读: +相关阅读: - [IoC 源码阅读](https://javadoop.com/post/spring-ioc) - [IoC & AOP 详解(快速搞懂)](./ioc-and-aop.md) @@ -791,4 +791,4 @@ public interface PasswordEncoder { - - - \ No newline at end of file + diff --git a/docs/system-design/framework/spring/spring-transaction.md b/docs/system-design/framework/spring/spring-transaction.md index b6f5d749..e878d6da 100644 --- a/docs/system-design/framework/spring/spring-transaction.md +++ b/docs/system-design/framework/spring/spring-transaction.md @@ -655,7 +655,6 @@ public class DefaultAopProxyFactory implements AopProxyFactory, Serializable { #### Spring AOP 自调用问题 - 当一个方法被标记了`@Transactional` 注解的时候,Spring 事务管理器只会在被其他类方法调用的时候生效,而不会在一个类中方法调用生效。 这是因为 Spring AOP 工作原理决定的。因为 Spring AOP 使用动态代理来实现事务的管理,它会在运行的时候为带有 `@Transactional` 注解的方法生成代理对象,并在方法调用的前后应用事物逻辑。如果该方法被其他类调用我们的代理对象就会拦截方法调用并处理事务。但是在一个类中的其他方法内部调用的时候,我们代理对象就无法拦截到这个内部调用,因此事务也就失效了。 @@ -717,4 +716,4 @@ private void method1() { - [Spring 事务传播行为详解](https://segmentfault.com/a/1190000013341344):[https://segmentfault.com/a/1190000013341344](https://segmentfault.com/a/1190000013341344) - 全面分析 Spring 的编程式事务管理及声明式事务管理:[https://www.ibm.com/developerworks/cn/education/opensource/os-cn-spring-trans/index.html](https://www.ibm.com/developerworks/cn/education/opensource/os-cn-spring-trans/index.html) - \ No newline at end of file + diff --git a/docs/system-design/framework/spring/springboot-knowledge-and-questions-summary.md b/docs/system-design/framework/spring/springboot-knowledge-and-questions-summary.md index d6a72c11..7ced5db9 100644 --- a/docs/system-design/framework/spring/springboot-knowledge-and-questions-summary.md +++ b/docs/system-design/framework/spring/springboot-knowledge-and-questions-summary.md @@ -9,4 +9,4 @@ tag: - \ No newline at end of file + diff --git a/docs/system-design/framework/spring/springboot-source-code.md b/docs/system-design/framework/spring/springboot-source-code.md index f98c9c2c..d39f92c8 100644 --- a/docs/system-design/framework/spring/springboot-source-code.md +++ b/docs/system-design/framework/spring/springboot-source-code.md @@ -11,5 +11,4 @@ tag: - - \ No newline at end of file + diff --git a/docs/system-design/schedule-task.md b/docs/system-design/schedule-task.md index dd448c19..4c599895 100644 --- a/docs/system-design/schedule-task.md +++ b/docs/system-design/schedule-task.md @@ -357,17 +357,17 @@ public ReturnT myAnnotationJobHandler(String param) throws Exception { 由于 SchedulerX 属于人民币产品,我这里就不过多介绍。PowerJob 官方也对比过其和 QuartZ、XXL-JOB 以及 SchedulerX。 -| | QuartZ | xxl-job | SchedulerX 2.0 | PowerJob | -| -------------- | ------------------------------------------ | ---------------------------------------- | ------------------------------------------------- | ------------------------------------------------------------ | -| 定时类型 | CRON | CRON | CRON、固定频率、固定延迟、OpenAPI | **CRON、固定频率、固定延迟、OpenAPI** | +| | QuartZ | xxl-job | SchedulerX 2.0 | PowerJob | +| -------------- | ------------------------------------------- | ------------------------------------------ | ---------------------------------------------------- | --------------------------------------------------------------- | +| 定时类型 | CRON | CRON | CRON、固定频率、固定延迟、OpenAPI | **CRON、固定频率、固定延迟、OpenAPI** | | 任务类型 | 内置 Java | 内置 Java、GLUE Java、Shell、Python 等脚本 | 内置 Java、外置 Java(FatJar)、Shell、Python 等脚本 | **内置 Java、外置 Java(容器)、Shell、Python 等脚本** | -| 分布式计算 | 无 | 静态分片 | MapReduce 动态分片 | **MapReduce 动态分片** | -| 在线任务治理 | 不支持 | 支持 | 支持 | **支持** | -| 日志白屏化 | 不支持 | 支持 | 不支持 | **支持** | -| 调度方式及性能 | 基于数据库锁,有性能瓶颈 | 基于数据库锁,有性能瓶颈 | 不详 | **无锁化设计,性能强劲无上限** | -| 报警监控 | 无 | 邮件 | 短信 | **WebHook、邮件、钉钉与自定义扩展** | -| 系统依赖 | JDBC 支持的关系型数据库(MySQL、Oracle...) | MySQL | 人民币 | **任意 Spring Data Jpa 支持的关系型数据库(MySQL、Oracle...)** | -| DAG 工作流 | 不支持 | 不支持 | 支持 | **支持** | +| 分布式计算 | 无 | 静态分片 | MapReduce 动态分片 | **MapReduce 动态分片** | +| 在线任务治理 | 不支持 | 支持 | 支持 | **支持** | +| 日志白屏化 | 不支持 | 支持 | 不支持 | **支持** | +| 调度方式及性能 | 基于数据库锁,有性能瓶颈 | 基于数据库锁,有性能瓶颈 | 不详 | **无锁化设计,性能强劲无上限** | +| 报警监控 | 无 | 邮件 | 短信 | **WebHook、邮件、钉钉与自定义扩展** | +| 系统依赖 | JDBC 支持的关系型数据库(MySQL、Oracle...) | MySQL | 人民币 | **任意 Spring Data Jpa 支持的关系型数据库(MySQL、Oracle...)** | +| DAG 工作流 | 不支持 | 不支持 | 支持 | **支持** | ## 定时任务方案总结 @@ -381,4 +381,4 @@ XXL-JOB 2015 年推出,已经经过了很多年的考验。XXL-JOB 轻量级 这篇文章并没有介绍到实际使用,但是,并不代表实际使用不重要。我在写这篇文章之前,已经动手写过相应的 Demo。像 Quartz,我在大学那会就用过。不过,当时用的是 Spring 。为了能够更好地体验,我自己又在 Spring Boot 上实际体验了一下。如果你并没有实际使用某个框架,就直接说它并不好用的话,是站不住脚的。 - \ No newline at end of file + diff --git a/docs/system-design/security/advantages-and-disadvantages-of-jwt.md b/docs/system-design/security/advantages-and-disadvantages-of-jwt.md index 2fa0bc41..62ce20ef 100644 --- a/docs/system-design/security/advantages-and-disadvantages-of-jwt.md +++ b/docs/system-design/security/advantages-and-disadvantages-of-jwt.md @@ -179,4 +179,4 @@ JWT 也不是银弹,也有很多缺陷,具体是选择 JWT 还是 Session - CSRF protection with JSON Web JWTs: - Invalidating JSON Web JWTs: - \ No newline at end of file + diff --git a/docs/system-design/security/data-desensitization.md b/docs/system-design/security/data-desensitization.md index 49d18628..524aa19d 100644 --- a/docs/system-design/security/data-desensitization.md +++ b/docs/system-design/security/data-desensitization.md @@ -40,27 +40,27 @@ tag: Hutool 一个 Java 基础工具类,对文件、流、加密解密、转码、正则、线程、XML 等 JDK 方法进行封装,组成各种 Util 工具类,同时提供以下组件: -| 模块 | 介绍 | -| :----------------: | :----------------------------------------------------------: | -| hutool-aop | JDK 动态代理封装,提供非 IOC 下的切面支持 | -| hutool-bloomFilter | 布隆过滤,提供一些 Hash 算法的布隆过滤 | -| hutool-cache | 简单缓存实现 | -| hutool-core | 核心,包括 Bean 操作、日期、各种 Util 等 | -| hutool-cron | 定时任务模块,提供类 Crontab 表达式的定时任务 | -| hutool-crypto | 加密解密模块,提供对称、非对称和摘要算法封装 | -| hutool-db | JDBC 封装后的数据操作,基于 ActiveRecord 思想 | -| hutool-dfa | 基于 DFA 模型的多关键字查找 | +| 模块 | 介绍 | +| :----------------: | :---------------------------------------------------------------------------: | +| hutool-aop | JDK 动态代理封装,提供非 IOC 下的切面支持 | +| hutool-bloomFilter | 布隆过滤,提供一些 Hash 算法的布隆过滤 | +| hutool-cache | 简单缓存实现 | +| hutool-core | 核心,包括 Bean 操作、日期、各种 Util 等 | +| hutool-cron | 定时任务模块,提供类 Crontab 表达式的定时任务 | +| hutool-crypto | 加密解密模块,提供对称、非对称和摘要算法封装 | +| hutool-db | JDBC 封装后的数据操作,基于 ActiveRecord 思想 | +| hutool-dfa | 基于 DFA 模型的多关键字查找 | | hutool-extra | 扩展模块,对第三方封装(模板引擎、邮件、Servlet、二维码、Emoji、FTP、分词等) | -| hutool-http | 基于 HttpUrlConnection 的 Http 客户端封装 | -| hutool-log | 自动识别日志实现的日志门面 | -| hutool-script | 脚本执行封装,例如 Javascript | -| hutool-setting | 功能更强大的 Setting 配置文件和 Properties 封装 | -| hutool-system | 系统参数调用封装(JVM 信息等) | -| hutool-json | JSON 实现 | -| hutool-captcha | 图片验证码实现 | -| hutool-poi | 针对 POI 中 Excel 和 Word 的封装 | -| hutool-socket | 基于 Java 的 NIO 和 AIO 的 Socket 封装 | -| hutool-jwt | JSON Web Token (JWT) 封装实现 | +| hutool-http | 基于 HttpUrlConnection 的 Http 客户端封装 | +| hutool-log | 自动识别日志实现的日志门面 | +| hutool-script | 脚本执行封装,例如 Javascript | +| hutool-setting | 功能更强大的 Setting 配置文件和 Properties 封装 | +| hutool-system | 系统参数调用封装(JVM 信息等) | +| hutool-json | JSON 实现 | +| hutool-captcha | 图片验证码实现 | +| hutool-poi | 针对 POI 中 Excel 和 Word 的封装 | +| hutool-socket | 基于 Java 的 NIO 和 AIO 的 Socket 封装 | +| hutool-jwt | JSON Web Token (JWT) 封装实现 | 可以根据需求对每个模块单独引入,也可以通过引入`hutool-all`方式引入所有模块,本文所使用的数据脱敏工具就是在 `hutool.core` 模块。 @@ -480,4 +480,4 @@ public class Account { - 聊聊如何自定义数据脱敏: - FastJSON 实现数据脱敏: - \ No newline at end of file + diff --git a/docs/system-design/security/design-of-authority-system.md b/docs/system-design/security/design-of-authority-system.md index 34f14e57..2bc1358f 100644 --- a/docs/system-design/security/design-of-authority-system.md +++ b/docs/system-design/security/design-of-authority-system.md @@ -210,4 +210,4 @@ head: - 选择合适的权限模型:https://docs.authing.cn/v2/guides/access-control/choose-the-right-access-control-model.html - \ No newline at end of file + diff --git a/docs/system-design/security/encryption-algorithms.md b/docs/system-design/security/encryption-algorithms.md index 1d6f055a..6544a5f8 100644 --- a/docs/system-design/security/encryption-algorithms.md +++ b/docs/system-design/security/encryption-algorithms.md @@ -357,4 +357,4 @@ DSA 算法签名过程: - AES-GCM 加密简介: - Java AES 256 GCM Encryption and Decryption Example | JCE Unlimited Strength: - \ No newline at end of file + diff --git a/docs/system-design/security/jwt-intro.md b/docs/system-design/security/jwt-intro.md index 2d38ad39..7aecbe7a 100644 --- a/docs/system-design/security/jwt-intro.md +++ b/docs/system-design/security/jwt-intro.md @@ -165,4 +165,4 @@ HMACSHA256( 6. Payload 要加入 `exp` (JWT 的过期时间),永久有效的 JWT 不合理。并且,JWT 的过期时间不易过长。 7. …… - \ No newline at end of file + diff --git a/docs/system-design/security/sentive-words-filter.md b/docs/system-design/security/sentive-words-filter.md index 9fee7028..2be3d0c1 100644 --- a/docs/system-design/security/sentive-words-filter.md +++ b/docs/system-design/security/sentive-words-filter.md @@ -99,4 +99,4 @@ System.out.println(matchStrList2); - [一种敏感词自动过滤管理系统](https://patents.google.com/patent/CN101964000B) - [一种网络游戏中敏感词过滤方法及系统](https://patents.google.com/patent/CN103714160A/zh) - \ No newline at end of file + diff --git a/docs/system-design/security/sso-intro.md b/docs/system-design/security/sso-intro.md index d709f9e5..77404001 100644 --- a/docs/system-design/security/sso-intro.md +++ b/docs/system-design/security/sso-intro.md @@ -121,4 +121,4 @@ SSO 英文全称 Single Sign On,单点登录。SSO 是在多个应用系统中 - 关于方案:这次设计方案更多是提供实现思路。如果涉及到 APP 用户登录等情况,在访问 SSO 服务时,增加对 APP 的签名验证就好了。当然,如果有无线网关,验证签名不是问题。 - 关于时序图:时序图中并没有包含所有场景,只列举了核心/主要场景,另外对于一些不影响理解思路的消息能省就省了。 - \ No newline at end of file + diff --git a/docs/system-design/system-design-questions.md b/docs/system-design/system-design-questions.md index 3c18c79f..e34d5cc4 100644 --- a/docs/system-design/system-design-questions.md +++ b/docs/system-design/system-design-questions.md @@ -10,4 +10,4 @@ icon: "design" - \ No newline at end of file + diff --git a/docs/system-design/web-real-time-message-push.md b/docs/system-design/web-real-time-message-push.md index d927def7..fda58073 100644 --- a/docs/system-design/web-real-time-message-push.md +++ b/docs/system-design/web-real-time-message-push.md @@ -446,4 +446,4 @@ MQTT 协议为什么在物联网(IOT)中如此受偏爱?而不是其它协 | WebSocket | 除了最初建立连接时用 HTTP 协议,其他时候都是直接基于 TCP 协议进行通信的,可以实现客户端和服务端的全双工通信。 | 性能高、开销小 | 对开发人员要求更高,实现相对复杂一些 | | MQTT | 基于发布/订阅(publish/subscribe)模式的轻量级通讯协议,通过订阅相应的主题来获取消息。 | 成熟稳定,轻量级 | 对开发人员要求更高,实现相对复杂一些 | - \ No newline at end of file + diff --git a/docs/tools/docker/docker-in-action.md b/docs/tools/docker/docker-in-action.md index 623dd519..3c7198cf 100644 --- a/docs/tools/docker/docker-in-action.md +++ b/docs/tools/docker/docker-in-action.md @@ -631,4 +631,4 @@ REPOSITORY TAG IMAGE ID CREATED my_tomcat 1.0 79ab047fade5 7 minutes ago 463MB ``` - \ No newline at end of file + diff --git a/docs/tools/docker/docker-intro.md b/docs/tools/docker/docker-intro.md index 4c9d7487..18b93e17 100644 --- a/docs/tools/docker/docker-intro.md +++ b/docs/tools/docker/docker-intro.md @@ -298,4 +298,4 @@ LXC 技术主要是借助 Linux 内核中提供的 CGroup 功能和 namespace - [LXC vs Docker: Why Docker is Better](https://www.upguard.com/articles/docker-vs-lxc "LXC vs Docker: Why Docker is Better") - [CGroup 介绍、应用实例及原理描述](https://www.ibm.com/developerworks/cn/linux/1506_cgroup/index.html "CGroup 介绍、应用实例及原理描述") - \ No newline at end of file + diff --git a/docs/tools/git/git-intro.md b/docs/tools/git/git-intro.md index c4806fec..c2cf8000 100644 --- a/docs/tools/git/git-intro.md +++ b/docs/tools/git/git-intro.md @@ -246,4 +246,4 @@ git push origin - [猴子都能懂得 Git 入门](https://backlog.com/git-tutorial/cn/intro/intro1_1.html):有趣的讲解。 - [Pro Git book](https://git-scm.com/book/zh/v2):国外的一本 Git 书籍,被翻译成多国语言,质量很高。 - \ No newline at end of file + diff --git a/docs/tools/git/github-tips.md b/docs/tools/git/github-tips.md index c6ddf263..25df8592 100644 --- a/docs/tools/git/github-tips.md +++ b/docs/tools/git/github-tips.md @@ -147,4 +147,4 @@ GitHub Actions 有一个官方市场,上面有非常多别人提交的 Actions 另外,这篇文章中,我并没有提到 Github 搜索技巧。在我看来,Github 搜索技巧不必要记网上那些文章说的各种命令啥的,真没啥卵用。你会发现你用的最多的还是关键字搜索以及 Github 自带的筛选功能。 - \ No newline at end of file + diff --git a/docs/tools/gradle/gradle-core-concepts.md b/docs/tools/gradle/gradle-core-concepts.md index c02ace72..d699351f 100644 --- a/docs/tools/gradle/gradle-core-concepts.md +++ b/docs/tools/gradle/gradle-core-concepts.md @@ -303,4 +303,4 @@ Gradle 支持单项目和多项目构建。在初始化阶段,Gradle 确定哪 - 手把手带你自定义 Gradle 插件 —— Gradle 系列(2): - Gradle 爬坑指南 -- 理解 Plugin、Task、构建流程: - \ No newline at end of file + diff --git a/docs/tools/maven/maven-best-practices.md b/docs/tools/maven/maven-best-practices.md index 647a9380..120c194e 100644 --- a/docs/tools/maven/maven-best-practices.md +++ b/docs/tools/maven/maven-best-practices.md @@ -230,4 +230,4 @@ jacoco-maven-plugin 使用示例: ## 总结 -Maven 是一个强大的工具,可以简化 Java 项目的构建过程和依赖关系管理。通过遵循这些最佳实践和技巧,我们可以优化 Maven 的使用并改善我们的 Java 开发体验。请记住使用标准目录结构,有效管理依赖关系,利用不同环境的配置文件,并将项目与持续集成系统集成,以确保构建一致。 \ No newline at end of file +Maven 是一个强大的工具,可以简化 Java 项目的构建过程和依赖关系管理。通过遵循这些最佳实践和技巧,我们可以优化 Maven 的使用并改善我们的 Java 开发体验。请记住使用标准目录结构,有效管理依赖关系,利用不同环境的配置文件,并将项目与持续集成系统集成,以确保构建一致。 diff --git a/docs/tools/maven/maven-core-concepts.md b/docs/tools/maven/maven-core-concepts.md index db3f7f9e..07f46bc5 100644 --- a/docs/tools/maven/maven-core-concepts.md +++ b/docs/tools/maven/maven-core-concepts.md @@ -461,4 +461,4 @@ Maven 插件被分为下面两种类型: - 解决 maven 依赖冲突,这篇就够了!: - Multi-Module Project with Maven: - \ No newline at end of file + diff --git a/docs/zhuanlan/back-end-interview-high-frequency-system-design-and-scenario-questions.md b/docs/zhuanlan/back-end-interview-high-frequency-system-design-and-scenario-questions.md index d148bea1..ee848d00 100644 --- a/docs/zhuanlan/back-end-interview-high-frequency-system-design-and-scenario-questions.md +++ b/docs/zhuanlan/back-end-interview-high-frequency-system-design-and-scenario-questions.md @@ -19,4 +19,4 @@ category: 知识星球 ![《后端面试高频系统设计&场景题》](https://oss.javaguide.cn/xingqiu/back-end-interview-high-frequency-system-design-and-scenario-questions-fengmian.png) - \ No newline at end of file +