1
0
mirror of https://github.com/Snailclimb/JavaGuide synced 2025-08-01 16:28:03 +08:00

style: update linter

This commit is contained in:
Mr.Hope 2023-10-27 06:44:02 +08:00
parent 5e58e830eb
commit 7ea99a88d7
211 changed files with 1175 additions and 1197 deletions

View File

@ -143,7 +143,7 @@ JavaGuide 知识星球优质主题汇总传送门:<https://www.yuque.com/snail
![知识星球30元优惠卷](https://oss.javaguide.cn/xingqiu/xingqiuyouhuijuan-30.jpg)
进入星球之后,记得查看 **[星球使用指南](https://t.zsxq.com/0d18KSarv)** (一定要看!!!) 和 **[星球优质主题汇总](https://www.yuque.com/snailclimb/rpkqw1/ncxpnfmlng08wlf1)** 。另外,建议你添加一下我的个人微信( **javaguide1024** ,备注 **“星球”** ,生活号,球友专属),方便后续交流沟通。
进入星球之后,记得查看 **[星球使用指南](https://t.zsxq.com/0d18KSarv)** (一定要看!!!) 和 **[星球优质主题汇总](https://www.yuque.com/snailclimb/rpkqw1/ncxpnfmlng08wlf1)** 。另外,建议你添加一下我的个人微信( **javaguide1024** ,备注 **“星球”** ,生活号,球友专属),方便后续交流沟通。
![个人微信](https://oss.javaguide.cn/xingqiu/weixin-guidege666.jpeg)

View File

@ -42,7 +42,7 @@ icon: "java"
Java 8 算是一个里程碑式的版本,现在一般企业还是用 Java 8 比较多。掌握 Java 8 的一些新特性比如 Lambda、Stream API 还是挺有必要的。这块的话,我推荐 **[《Java 8 实战》](https://book.douban.com/subject/26772632/)** 这本书。
**[《Java 编程的逻辑》](https://book.douban.com/subject/30133440/)**
**[《Java 编程的逻辑》](https://book.douban.com/subject/30133440/)**
![《Java编程的逻辑》](https://oss.javaguide.cn/github/javaguide/books/image-20230721153650488.png)
@ -131,7 +131,7 @@ Java 8 算是一个里程碑式的版本,现在一般企业还是用 Java 8
- **IDEA**:熟悉基本操作以及常用快捷。相关资料: [《IntelliJ IDEA 简体中文专题教程》](https://github.com/judasn/IntelliJ-IDEA-Tutorial) 。
- **Maven**:强烈建议学习常用框架之前可以提前花几天时间学习一下**Maven**的使用。(到处找 Jar 包,下载 Jar 包是真的麻烦费事,使用 Maven 可以为你省很多事情)。相关阅读:[Maven 核心概念总结](https://javaguide.cn/tools/maven/maven-core-concepts.html)。
- **Git**:基本的 Git 技能也是必备的,试着在学习的过程中将自己的代码托管在 Github 上。相关阅读:[Git 核心概念总结](https://javaguide.cn/tools/git/git-intro.html)。
- **Docker**:学着用 Docker 安装学习中需要用到的软件比如 MySQL ,这样方便很多,可以为你节省不少时间。相关资料:[《Docker - 从入门到实践》](https://yeasy.gitbook.io/docker_practice/)
- **Docker**:学着用 Docker 安装学习中需要用到的软件比如 MySQL ,这样方便很多,可以为你节省不少时间。相关资料:[《Docker - 从入门到实践》](https://yeasy.gitbook.io/docker_practice/) 。
除了这些工具之外,我强烈建议你一定要搞懂 GitHub 的使用。一些使用 GitHub 的小技巧,你可以看[Github 实用小技巧总结](https://javaguide.cn/tools/git/github-tips.html)这篇文章。

View File

@ -26,8 +26,8 @@ tag:
上图存在错误:
1. 插入排序的最好时间复杂度为 O(n) 而不是 O(n^2)
2. 希尔排序的平均时间复杂度为 O(nlogn)
1. 插入排序的最好时间复杂度为 $O(n)$ 而不是 $O(n^2)$
2. 希尔排序的平均时间复杂度为 $O(nlogn)$。
**图片名词解释:**
@ -38,8 +38,8 @@ tag:
### 术语说明
- **稳定**:如果 A 原本在 B 前面,而 A=B排序之后 A 仍然在 B 的前面。
- **不稳定**:如果 A 原本在 B 的前面,而 A=B排序之后 A 可能会出现在 B 的后面。
- **稳定**:如果 A 原本在 B 前面,而 $A=B$,排序之后 A 仍然在 B 的前面。
- **不稳定**:如果 A 原本在 B 的前面,而 $A=B$,排序之后 A 可能会出现在 B 的后面。
- **内排序**:所有排序操作都在内存中完成。
- **外排序**:由于数据太大,因此把数据放在磁盘中,而排序通过磁盘和内存的数据传输才能进行。
- **时间复杂度**:定性描述一个算法执行所耗费的时间。
@ -55,7 +55,7 @@ tag:
比较类排序的优势是,适用于各种规模的数据,也不在乎数据的分布,都能进行排序。可以说,比较排序适用于一切需要排序的情况。
而**计数排序**、**基数排序**、**桶排序**则属于**非比较类排序算法**。非比较排序不通过比较来决定元素间的相对次序,而是通过确定每个元素之前,应该有多少个元素来排序。由于它可以突破基于比较排序的时间下界,以线性时间运行,因此称为线性时间非比较类排序。 非比较排序只要确定每个元素之前的已有的元素个数即可,所有一次遍历即可解决。算法时间复杂度 `O(n)`
而**计数排序**、**基数排序**、**桶排序**则属于**非比较类排序算法**。非比较排序不通过比较来决定元素间的相对次序,而是通过确定每个元素之前,应该有多少个元素来排序。由于它可以突破基于比较排序的时间下界,以线性时间运行,因此称为线性时间非比较类排序。 非比较排序只要确定每个元素之前的已有的元素个数即可,所有一次遍历即可解决。算法时间复杂度 $O(n)$
非比较排序时间复杂度底,但由于非比较排序需要占用空间来确定唯一位置。所以对数据规模和数据分布有一定的要求。
@ -109,13 +109,13 @@ public static int[] bubbleSort(int[] arr) {
### 算法分析
- **稳定性**:稳定
- **时间复杂度**最佳O(n) 最差O(n2) 平均O(n2)
- **空间复杂度**O(1)
- **时间复杂度**:最佳:$O(n)$ ,最差:$O(n^2)$ 平均:$O(n^2)$
- **空间复杂度**$O(1)$
- **排序方式**In-place
## 选择排序 (Selection Sort)
选择排序是一种简单直观的排序算法,无论什么数据进去都是 `O(n²)` 的时间复杂度。所以用到它的时候,数据规模越小越好。唯一的好处可能就是不占用额外的内存空间了吧。它的工作原理:首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最小(大)元素,然后放到已排序序列的末尾。以此类推,直到所有元素均排序完毕。
选择排序是一种简单直观的排序算法,无论什么数据进去都是 $O(n^2)$ 的时间复杂度。所以用到它的时候,数据规模越小越好。唯一的好处可能就是不占用额外的内存空间了吧。它的工作原理:首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最小(大)元素,然后放到已排序序列的末尾。以此类推,直到所有元素均排序完毕。
### 算法步骤
@ -156,13 +156,13 @@ public static int[] selectionSort(int[] arr) {
### 算法分析
- **稳定性**:不稳定
- **时间复杂度**最佳O(n2) 最差O(n2) 平均O(n2)
- **空间复杂度**O(1)
- **时间复杂度**:最佳:$O(n^2)$ ,最差:$O(n^2)$ 平均:$O(n^2)$
- **空间复杂度**$O(1)$
- **排序方式**In-place
## 插入排序 (Insertion Sort)
插入排序是一种简单直观的排序算法。它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入。插入排序在实现上,通常采用 in-place 排序(即只需用到 `O(1)` 的额外空间的排序),因而在从后向前扫描过程中,需要反复把已排序元素逐步向后挪位,为最新元素提供插入空间。
插入排序是一种简单直观的排序算法。它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入。插入排序在实现上,通常采用 in-place 排序(即只需用到 $O(1)$ 的额外空间的排序),因而在从后向前扫描过程中,需要反复把已排序元素逐步向后挪位,为最新元素提供插入空间。
插入排序的代码实现虽然没有冒泡排序和选择排序那么简单粗暴,但它的原理应该是最容易理解的了,因为只要打过扑克牌的人都应该能够秒懂。插入排序是一种最简单直观的排序算法,它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入。
@ -206,25 +206,25 @@ public static int[] insertionSort(int[] arr) {
### 算法分析
- **稳定性**:稳定
- **时间复杂度**最佳O(n) 最差O(n2) 平均O(n2)
- **空间复杂度**O(1)
- **时间复杂度**:最佳:$O(n)$ ,最差:$O(n^2)$ 平均:$O(n2)$
- **空间复杂度**O(1)$
- **排序方式**In-place
## 希尔排序 (Shell Sort)
希尔排序是希尔 (Donald Shell) 于 1959 年提出的一种排序算法。希尔排序也是一种插入排序,它是简单插入排序经过改进之后的一个更高效的版本,也称为递减增量排序算法,同时该算法是冲破 `O(n²)` 的第一批算法之一。
希尔排序是希尔 (Donald Shell) 于 1959 年提出的一种排序算法。希尔排序也是一种插入排序,它是简单插入排序经过改进之后的一个更高效的版本,也称为递减增量排序算法,同时该算法是冲破 $O(n^2)$ 的第一批算法之一。
希尔排序的基本思想是:先将整个待排序的记录序列分割成为若干子序列分别进行直接插入排序,待整个序列中的记录 “基本有序” 时,再对全体记录进行依次直接插入排序。
### 算法步骤
我们来看下希尔排序的基本步骤,在此我们选择增量 `gap=length/2`,缩小增量继续以 `gap = gap/2` 的方式,这种增量选择我们可以用一个序列来表示,`{n/2, (n/2)/2, ..., 1}`,称为**增量序列**。希尔排序的增量序列的选择与证明是个数学难题,我们选择的这个增量序列是比较常用的,也是希尔建议的增量,称为希尔增量,但其实这个增量序列不是最优的。此处我们做示例使用希尔增量。
我们来看下希尔排序的基本步骤,在此我们选择增量 $gap=length/2$,缩小增量继续以 $gap = gap/2$ 的方式,这种增量选择我们可以用一个序列来表示,$\lbrace \frac{n}{2}, \frac{(n/2)}{2}, \dots, 1 \rbrace$,称为**增量序列**。希尔排序的增量序列的选择与证明是个数学难题,我们选择的这个增量序列是比较常用的,也是希尔建议的增量,称为希尔增量,但其实这个增量序列不是最优的。此处我们做示例使用希尔增量。
先将整个待排序的记录序列分割成为若干子序列分别进行直接插入排序,具体算法描述:
- 选择一个增量序列 `{t1, t2, …, tk}`,其中 `(ti>tj, i<j, tk=1)`
- 选择一个增量序列 $\lbrace t_1, t_2, \dots, t_k \rbrace$,其中 $t_i \gt t_j, i \lt j, t_k = 1$
- 按增量序列个数 k对序列进行 k 趟排序;
- 每趟排序,根据对应的增量 `t`,将待排序列分割成若干长度为 `m` 的子序列,分别对各子表进行直接插入排序。仅增量因子为 1 时,整个序列作为一个表来处理,表长度即为整个序列的长度。
- 每趟排序,根据对应的增量 $t$,将待排序列分割成若干长度为 $m$ 的子序列,分别对各子表进行直接插入排序。仅增量因子为 1 时,整个序列作为一个表来处理,表长度即为整个序列的长度。
### 图解算法
@ -263,24 +263,24 @@ public static int[] shellSort(int[] arr) {
### 算法分析
- **稳定性**:不稳定
- **时间复杂度**:最佳:O(nlogn) 最差O(n^2) 平均O(nlogn)
- **空间复杂度**`O(1)`
- **时间复杂度**:最佳:$O(nlogn)$ 最差:$O(n^2)$ 平均:$O(nlogn)$
- **空间复杂度**$O(1)$
## 归并排序 (Merge Sort)
归并排序是建立在归并操作上的一种有效的排序算法。该算法是采用分治法 (Divide and Conquer) 的一个非常典型的应用。归并排序是一种稳定的排序方法。将已有序的子序列合并,得到完全有序的序列;即先使每个子序列有序,再使子序列段间有序。若将两个有序表合并成一个有序表,称为 2 - 路归并。
和选择排序一样,归并排序的性能不受输入数据的影响,但表现比选择排序好的多,因为始终都是 `O(nlogn)` 的时间复杂度。代价是需要额外的内存空间。
和选择排序一样,归并排序的性能不受输入数据的影响,但表现比选择排序好的多,因为始终都是 $O(nlogn)$ 的时间复杂度。代价是需要额外的内存空间。
### 算法步骤
归并排序算法是一个递归过程,边界条件为当输入序列仅有一个元素时,直接返回,具体过程如下:
1. 如果输入内只有一个元素,则直接返回,否则将长度为 `n` 的输入序列分成两个长度为 `n/2` 的子序列;
1. 如果输入内只有一个元素,则直接返回,否则将长度为 $n$ 的输入序列分成两个长度为 $n/2$ 的子序列;
2. 分别对这两个子序列进行归并排序,使子序列变为有序状态;
3. 设定两个指针,分别指向两个已经排序子序列的起始位置;
4. 比较两个指针所指向的元素,选择相对小的元素放入到合并空间(用于存放排序结果),并移动指针到下一位置;
5. 重复步骤 3 ~4 直到某一指针达到序列尾;
5. 重复步骤 3 ~ 4 直到某一指针达到序列尾;
6. 将另一序列剩下的所有元素直接复制到合并序列尾。
### 图解算法
@ -346,8 +346,8 @@ public static int[] merge(int[] arr_1, int[] arr_2) {
### 算法分析
- **稳定性**:稳定
- **时间复杂度**最佳O(nlogn) 最差O(nlogn) 平均O(nlogn)
- **空间复杂度**O(n)
- **时间复杂度**:最佳:$O(nlogn)$ 最差:$O(nlogn)$ 平均:$O(nlogn)$
- **空间复杂度**$O(n)$
## 快速排序 (Quick Sort)
@ -401,8 +401,8 @@ public static void quickSort(int[] array, int low, int high) {
### 算法分析
- **稳定性**:不稳定
- **时间复杂度**最佳O(nlogn) 最差O(nlogn)平均O(nlogn)
- **空间复杂度**O(logn)
- **时间复杂度**:最佳:$O(nlogn)$ 最差:$O(nlogn)$,平均:$O(nlogn)$
- **空间复杂度**$O(logn)$
## 堆排序 (Heap Sort)
@ -410,9 +410,9 @@ public static void quickSort(int[] array, int low, int high) {
### 算法步骤
1. 将初始待排序列 `(R1, R2, ……, Rn)` 构建成大顶堆,此堆为初始的无序区;
2. 将堆顶元素 `R[1]` 与最后一个元素 `R[n]` 交换,此时得到新的无序区 `(R1, R2, ……, Rn-1)` 和新的有序区 (Rn), 且满足 `R[1, 2, ……, n-1]<=R[n]`
3. 由于交换后新的堆顶 `R[1]` 可能违反堆的性质,因此需要对当前无序区 `(R1, R2, ……, Rn-1)` 调整为新堆,然后再次将 R [1] 与无序区最后一个元素交换,得到新的无序区 `(R1, R2, ……, Rn-2)` 和新的有序区 `(Rn-1, Rn)`。不断重复此过程直到有序区的元素个数为 `n-1`,则整个排序过程完成。
1. 将初始待排序列 $(R_1, R_2, \dots, R_n)$ 构建成大顶堆,此堆为初始的无序区;
2. 将堆顶元素 $R_1$ 与最后一个元素 $R_n$ 交换,此时得到新的无序区 $(R_1, R_2, \dots, R_{n-1})$ 和新的有序区 $R_n$, 且满足 $R_i \leqslant R_n (i \in 1, 2,\dots, n-1)$
3. 由于交换后新的堆顶 $R_1$ 可能违反堆的性质,因此需要对当前无序区 $(R_1, R_2, \dots, R_{n-1})$ 调整为新堆,然后再次将 $R_1$ 与无序区最后一个元素交换,得到新的无序区 $(R_1, R_2, \dots, R_{n-2})$ 和新的有序区 $(R_{n-1}, R_n)$。不断重复此过程直到有序区的元素个数为 $n-1$,则整个排序过程完成。
### 图解算法
@ -490,8 +490,8 @@ public static int[] heapSort(int[] arr) {
### 算法分析
- **稳定性**:不稳定
- **时间复杂度**最佳O(nlogn) 最差O(nlogn) 平均O(nlogn)
- **空间复杂度**O(1)
- **时间复杂度**:最佳:$O(nlogn)$ 最差:$O(nlogn)$ 平均:$O(nlogn)$
- **空间复杂度**$O(1)$
## 计数排序 (Counting Sort)
@ -503,10 +503,10 @@ public static int[] heapSort(int[] arr) {
1. 找出数组中的最大值 `max`、最小值 `min`
2. 创建一个新数组 `C`,其长度是 `max-min+1`,其元素默认值都为 0
3. 遍历原数组 `A` 中的元素 `A[i]`,以 `A[i]-min` 作为 `C` 数组的索引,以 `A[i]` 的值在 `A` 中元素出现次数作为 `C[A[i]-min]` 的值;
3. 遍历原数组 `A` 中的元素 `A[i]`,以 `A[i] - min` 作为 `C` 数组的索引,以 `A[i]` 的值在 `A` 中元素出现次数作为 `C[A[i] - min]` 的值;
4. 对 `C` 数组变形,**新元素的值是该元素与前一个元素值的和**,即当 `i>1``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<Integer> bucketSort(List<Integer> 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 桶排序**

View File

@ -384,4 +384,4 @@ public class Solution {
}
```
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -460,4 +460,4 @@ public class Main {
```
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -682,4 +682,4 @@ public class Solution {
}
```
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -309,4 +309,4 @@ root@21396d02c252:/data# redis-cli
(integer) 0
```
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -157,4 +157,4 @@ tag:
![深度优先搜索6](https://oss.javaguide.cn/github/javaguide/cs-basics/data-structure/depth-first-search6.png)
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -199,4 +199,4 @@ tag:
堆排序完成!
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -328,4 +328,4 @@ myStack.pop();//报错java.lang.IllegalArgumentException: Stack is empty.
- 消息队列
- 等等……
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -20,4 +20,4 @@ tag:
**相关阅读**[《红黑树深入剖析及 Java 实现》](https://zhuanlan.zhihu.com/p/24367771)(美团点评技术团队)
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -182,4 +182,4 @@ public void postOrder(TreeNode root){
}
```
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -112,4 +112,4 @@ DNSDomain Name System域名管理系统基于 UDP 协议,用于解决
- 《计算机网络自顶向下方法》(第七版)
- RTP 协议介绍:https://mthli.xyz/rtp-introduction/
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -102,4 +102,4 @@ ARP 的工作原理将分两种场景讨论:
![](./images/arp/arp_different_lan.png)
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -101,4 +101,4 @@ foo.example.com. A 192.0.2.23
- DNS Message Resource Record Field Formatshttp://www.tcpipguide.com/free/t_DNSMessageResourceRecordFieldFormats-2.htm
- Understanding Different Types of Record in DNS Serverhttps://www.mustbegeek.com/understanding-different-types-of-record-in-dns-server/
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -69,4 +69,4 @@ HTTP 状态码用于描述 HTTP 请求的结果,比如 2xx 就代表请求被
- https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
- https://segmentfault.com/a/1190000018264501
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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 耗费更多服务器资源。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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)
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -57,4 +57,4 @@ SOHO 子网的“代理人”,也就是和外界的窗口,通常由路由器
然而NAT 协议由于其独特性,存在着一些争议。比如,可能你已经注意到了,**NAT 协议在 LAN 以外,标识一个内部主机时,使用的是端口号,因为 IP 地址都是相同的。**这种将端口号作为主机寻址的行为,可能会引发一些误会。此外,路由器作为网络层的设备,修改了传输层的分组内容(修改了源 IP 地址和端口号同样是不规范的行为。但是尽管如此NAT 协议作为 IPv4 时代的产物,极大地方便了一些本来棘手的问题,一直被沿用至今。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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/
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -192,4 +192,4 @@ OSI 七层模型虽然失败了,但是却提供了很多不错的理论基础
- TCP/IP model vs OSI modelhttps://fiberbit.com.tw/tcpip-model-vs-osi-model/
- Data Encapsulation and the TCP/IP Protocol Stackhttps://docs.oracle.com/cd/E19683-01/806-4075/ipov-32/index.html
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -340,4 +340,4 @@ DNS 服务器自底向上可以依次分为以下几个层级(所有 DNS 服务
- HTTP1、HTTP2、HTTP3<https://juejin.cn/post/6855470356657307662>
- 如何看待 HTTP/3 - 车小胖的回答 - 知乎: <https://www.zhihu.com/question/302412059/answer/533223530>
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -187,4 +187,4 @@ ARP 协议,全称 **地址解析协议Address Resolution Protocol**
- 什么是 Internet 协议IP<https://www.cloudflare.com/zh-cn/learning/network-layer/internet-protocol/>
- What Is NAT and What Are the Benefits of NAT Firewalls?<https://community.fs.com/blog/what-is-nat-and-what-are-the-benefits-of-nat-firewalls.html>
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -83,4 +83,4 @@ TCP 是全双工通信,可以双向传输数据。任何一方都可以在数
- TCP and UDP Tutorialhttps://www.9tut.com/tcp-and-udp-tutorial
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -428,4 +428,4 @@ vim ~/.bash_profile
source /etc/profile
```
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -458,4 +458,4 @@ Thread[线程 2,5,main]waiting get resource1
- 从根上理解用户态与内核态https://juejin.cn/post/6923863670132850701
- 什么是僵尸进程与孤儿进程https://blog.csdn.net/a745233700/article/details/120715371
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -410,4 +410,4 @@ LRU 算法是实际使用中应用的比较多,也被认为是最接近 OPT
- 程序员的自我修养内存缺页错误https://liam.page/2017/09/01/page-fault/
- 虚拟内存的那点事儿https://juejin.cn/post/6844903507594575886
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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 !
```
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -324,4 +324,4 @@ Incorrect string value: '\xF0\x9F\x98\x98\xF0\x9F...' for column 'name' at row 1
- MySQL5.7 文档:<https://dev.mysql.com/doc/refman/5.7/en/charset.html>
- MySQL Connector/J 文档:<https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-charsets.html>
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -12,4 +12,4 @@ tag:
<!-- @include: @planet.snippet.md -->
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -283,4 +283,4 @@ WiredTiger 日志也会被压缩,默认使用的也是 Snappy 压缩算法。
- WiredTiger Storage Engine - MongoDB 官方文档:<https://www.mongodb.com/docs/manual/core/wiredtiger/>
- WiredTiger 存储引擎之一:基础数据结构分析:<https://mongoing.com/topic/archives-35143>
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -272,4 +272,4 @@ Rebalance 操作是比较耗费系统资源的,我们可以通过在业务低
- MongoDB 分片集群介绍 - 阿里云文档:<https://help.aliyun.com/document_detail/64561.html>
- 分片集群使用注意事项 - - 腾讯云文档:<https://cloud.tencent.com/document/product/240/44611>
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -954,4 +954,4 @@ OPTIMIZE [LOCAL | NO_WRITE_TO_BINLOG] TABLE tbl_name [, tbl_name] ...
7. 清除已有语句:\c
```
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -134,4 +134,4 @@ update tb_student A set A.age='19' where A.name=' 张三 ';
- 《MySQL 实战 45 讲》
- MySQL 5.6 参考手册:<https://dev.MySQL.com/doc/refman/5.6/en/>
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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/)
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -218,4 +218,4 @@ tag:
3. 事务回滚
4. 批量插入(如 `insert...select` 语句)
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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)
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -449,4 +449,4 @@ mysql> EXPLAIN SELECT `score`,`name` FROM `cus_order` ORDER BY `score` DESC;
篇幅问题,我这里只是简单介绍了一下 MySQL 执行计划,详细介绍请看:[MySQL 执行计划分析](./mysql-query-execution-plan.md)这篇文章。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -339,4 +339,4 @@ MySQL InnoDB 引擎使用 **redo log(重做日志)** 保证事务的**持久性*
- 《MySQL 是怎样运行的:从根儿上理解 MySQL》
- 《MySQL 技术 Innodb 存储引擎》
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -205,4 +205,4 @@ MySQL 中的查询缓存虽然能够提升数据库的查询性能,但是查
- RDS MySQL 查询缓存Query Cache的设置和使用 - 阿里元云数据库 RDS 文档:<https://help.aliyun.com/document_detail/41717.html>
- 8.10.3 The MySQL Query Cache - MySQL 官方文档:<https://dev.mysql.com/doc/refman/5.7/en/query-cache.html>
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -839,4 +839,4 @@ mysql> EXPLAIN SELECT `score`,`name` FROM `cus_order` ORDER BY `score` DESC;
- 深入剖析 MySQL 自增锁:<https://juejin.cn/post/6968420054287253540>
- 在数据库中不可重复读和幻读到底应该怎么分?:<https://www.zhihu.com/question/392569386>
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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 之后的时间 | 否 |
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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)
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -58,4 +58,4 @@ NoSQL 数据库主要可以分为下面四种类型:
- 什么是 NoSQL? - AWS<https://aws.amazon.com/cn/nosql/>
- NoSQL vs. SQL Databases - MongoDB 官方文档:<https://www.mongodb.com/zh-cn/nosql-explained/nosql-vs-sql>
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -115,4 +115,4 @@ Write Behind Pattern 和 Read/Write Through Pattern 很相似,两者都是由
Write Behind Pattern 下 db 的写性能非常高,非常适合一些数据经常变化又对数据一致性要求没那么高的场景,比如浏览量、点赞量。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -11,4 +11,4 @@ tag:
<!-- @include: @planet.snippet.md -->
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -11,4 +11,4 @@ tag:
<!-- @include: @planet.snippet.md -->
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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 官网对应的介绍:<https://redis.io/commands/?group=string>
@ -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<https://redis.io/docs/manual/data-types/data-types-tutorial/>
- Redis 存储对象信息是用 Hash 还是 String : <https://segmentfault.com/a/1190000040032006>
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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
- 布隆过滤器,位图,HyperLogLoghttps://hogwartsrico.github.io/2020/06/08/BloomFilter-HyperLogLog-BitMap/index.html
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -121,4 +121,4 @@ config set active-defrag-cycle-max 50
- Redis 核心技术与实战 - 极客时间 - 删除数据后为什么内存占用率还是很高https://time.geekbang.org/column/article/289140
- Redis 源码解析——内存分配:<https://shinerio.cc/2020/05/17/redis/Redis 源码解析内存管理>
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -196,4 +196,4 @@ AOF 校验机制是 Redis 在启动时对 AOF 文件进行检查,以判断文
- Redis AOF 持久化详解 - 程序员历小冰http://remcarpediem.net/article/376c55d8/
- Redis RDB 与 AOF 持久化 · Analyzehttps://wingsxdu.com/posts/database/redis/rdb-and-aof/
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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)
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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 的发现与处理:<https://mp.weixin.qq.com/s/FPYE1B839_8Yk1-YSiW-1Q>
- Redis 延迟问题全面排障指南https://mp.weixin.qq.com/s/mIc6a9mfEGdaNDD3MmfFsg
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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;
```
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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;
```
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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.52021 年 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因此只输出 1002detail 中是 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_recorduid 用户 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_recorduid 用户 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 次试卷 90011 人作答 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_infouid 用户 IDnick_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_infoexam_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_recorduid 用户 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_recorduid 用户 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
```
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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_recorduid 用户 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
```
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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_recorduid 用户 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_infoexam_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;
```
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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)
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -171,4 +171,4 @@ Shenyu 通过插件扩展功能,插件是 ShenYu 的灵魂,并且插件也
- API 网关 Kong 实战:<https://xie.infoq.cn/article/10e4dab2de0bdb6f2c3c93da6>
- Spring Cloud Gateway 原理介绍和应用:<https://blog.fintopia.tech/60e27b0e2078082a378ec5ed/>
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -9,4 +9,4 @@ category: 分布式
<!-- @include: @planet.snippet.md -->
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -355,4 +355,4 @@ Tinyid 的优缺点这里就不分析了,结合数据库号段模式的优缺
不过,本文主要介绍的是分布式 ID 的理论知识。在实际的面试中,面试官可能会结合具体的业务场景来考察你对分布式 ID 的设计,你可以参考这篇文章:[分布式 ID 设计指南](./distributed-id-design)(对于实际工作中分布式 ID 的设计也非常有帮助)。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -367,4 +367,4 @@ private static class LockData
这篇文章我们介绍了实现分布式锁的两种常见方式。至于具体选择 Redis 还是 ZooKeeper 来实现分布式锁,还是要看业务的具体需求。如果对性能要求比较高的话,建议使用 Redis 实现分布式锁。如果对可靠性要求比较高的话,建议使用 ZooKeeper 实现分布式锁。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -81,4 +81,4 @@ category: 分布式
- 分布式锁的应该具备的条件:互斥、高可用、可重入、高性能、非阻塞。
- 分布式锁的常见实现方式:关系型数据库比如 MySQL、分布式协调服务 ZooKeeper、分布式键值存储系统比如 Redis 、Etcd 。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -294,4 +294,4 @@ zkClient.setData().forPath("/node1/00001","c++".getBytes());//更新节点数据
List<String> childrenPaths = zkClient.getChildren().forPath("/node1");
```
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -280,4 +280,4 @@ ZAB 协议包括两种基本的模式,分别是
- 《从 Paxos 到 ZooKeeper 分布式一致性原理与实践》
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -365,4 +365,4 @@ tag:
如果忘了可以回去看看再次理解一下,如果有疑问和建议欢迎提出 🤝🤝🤝。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -9,4 +9,4 @@ category: 分布式
<!-- @include: @planet.snippet.md -->
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -141,9 +141,7 @@ CAP 理论这节我们也说过了:
> 分布式一致性的 3 种级别:
>
> 1. **强一致性**:系统写入了什么,读出来的就是什么。
>
> 2. **弱一致性**:不一定可以读取到最新写入的值,也不保证多少时间之后读取到的数据是最新的,只是会尽量保证某个时刻达到数据一致的状态。
>
> 3. **最终一致性**:弱一致性的升级版,系统会保证在一定时间内达到数据一致的状态。
>
> **业界比较推崇是最终一致性级别,但是某些对数据一致要求十分严格的场景比如银行转账还是要保证强一致性。**
@ -160,4 +158,4 @@ CAP 理论这节我们也说过了:
**ACID 是数据库事务完整性的理论CAP 是分布式系统设计理论BASE 是 CAP 理论中 AP 方案的延伸。**
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -142,4 +142,4 @@ Gossip 设计了两种可能的消息传播模式:**反熵Anti-Entropy**
- 《分布式协议与算法实战》
- 《Redis 设计与实现》
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -80,4 +80,4 @@ Basic Paxos 算法的仅能就单个值达成共识,为了能够对一系列
- https://zh.wikipedia.org/wiki/Paxos
- 分布式系统中的一致性与共识算法http://www.xuyasong.com/?p=1970
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -168,4 +168,4 @@ raft 的要求之一就是安全性不依赖于时间:系统不能仅仅因为
- https://github.com/ongardie/dissertation/blob/master/stanford.pdf
- https://knowledge-sharing.gitbooks.io/raft/content/chapter5.html
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -458,4 +458,4 @@ Dubbo 官方文档中还有一个关于这些[序列化协议的性能对比图]
![序列化协议的性能对比](https://oss.javaguide.cn/github/javaguide/distributed-system/rpc/dubbo-serialization-protocol-performance-comparison.png)
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -193,4 +193,4 @@ res = remoteFunc(req)
- RPC 其实比 HTTP 出现的要早,且比目前主流的 HTTP1.1 性能要更好,所以大部分公司内部都还在使用 RPC。
- **HTTP2.0****HTTP1.1** 的基础上做了优化,性能可能比很多 RPC 协议都要好,但由于是这几年才出来的,所以也不太可能取代掉 RPC。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -138,4 +138,4 @@ Dubbo 也是 Spring Cloud Alibaba 里面的一个组件。
关于这个问题的详细答案,请看这篇文章:[有了 HTTP 协议,为什么还要有 RPC ](http&rpc.md) 。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -154,4 +154,4 @@ public class GlobalErrorWebExceptionHandler implements ErrorWebExceptionHandler
- Creating a custom Spring Cloud Gateway Filter<https://spring.io/blog/2022/08/26/creating-a-custom-spring-cloud-gateway-filter>
- 全局异常处理: <https://zhuanlan.zhihu.com/p/347028665>
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -7,4 +7,4 @@ category: 高可用
<!-- @include: @planet.snippet.md -->
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -67,4 +67,4 @@ category: 高可用
- **定期检查/更换硬件:** 如果不是购买的云服务的话,定期还是需要对硬件进行一波检查的,对于一些需要更换或者升级的硬件,要及时更换或者升级。
- ……
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -210,4 +210,4 @@ Resilience4j 不仅提供限流,还提供了熔断、负载保护、自动重
- 超详细的 Guava RateLimiter 限流原理解析:<https://cloud.tencent.com/developer/article/1408819>
- 实战 Spring Cloud Gateway 之限流篇 👍:<https://www.aneasystone.com/archives/2020/08/spring-cloud-gateway-current-limiting.html>
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -148,4 +148,4 @@ category: 高可用
5. 数据库索引使用是否合理?
6. ……
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -43,4 +43,4 @@ category: 高可用
不过,这些文章大多也都是在介绍概念知识。目前,网上还缺少真正介绍具体要如何去实践落地异地多活架构的资料。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -78,4 +78,4 @@ category: 高可用
- 微服务之间调用超时的设置治理:<https://www.infoq.cn/article/eyrslar53l6hjm5yjgyx>
- 超时、重试和抖动回退:<https://aws.amazon.com/cn/builders-library/timeouts-retries-and-backoff-with-jitter/>
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -137,4 +137,4 @@ CPU 缓存是通过将最近使用的数据存储在高速缓存中来实现更
- Disruptor 高性能之道-等待策略:<http://wuwenliang.net/2022/02/28/Disruptor 高性能之道-等待策略/>
- 《Java 并发编程实战》- 40 | 案例分析(三):高性能队列 Disruptor<https://time.geekbang.org/column/article/98134>
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -438,4 +438,4 @@ private void customer(String message) {
- Kafka 官方文档https://kafka.apache.org/documentation/
- 极客时间—《Kafka 核心技术与实战》第 11 节:无消息丢失配置怎么实现?
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -287,4 +287,4 @@ Pulsar 更新记录可以直观看到项目是否还在维护https://gi
- KRaft: Apache Kafka Without ZooKeeperhttps://developer.confluent.io/learn/kraft/
- 消息队列的使用场景是什么样的https://mp.weixin.qq.com/s/4V1jI6RylJr7Jr9JsQe73A
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -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是不是有一点复杂 🤣,看英文图片和英文文档的时候
等等。。。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -266,4 +266,4 @@ ShardingSphere 的优势如下(摘自 ShardingSphere 官方文档:<https://s
- 引入分库分表之后,需要系统解决事务、分布式 id、无法 join 操作问题。
- ShardingSphere 绝对可以说是当前分库分表的首选ShardingSphere 的功能完善除了支持读写分离和分库分表还提供分布式事务、数据库治理等功能。另外ShardingSphere 的生态体系完善,社区活跃,文档完善,更新和发布比较频繁。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -16,4 +16,4 @@ head:
<!-- @include: @planet.snippet.md -->
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -145,4 +145,4 @@ tag:
希望你我可以有则改之,无则加勉。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -106,4 +106,4 @@ tag:
而高级的程序员往往都会在一件比较大的事情做完之后总结一下,做个 ppt写个博客啥的记录下来。这样既对自己的工作是一个归纳也可以分享给其它同学促进团队的共同成长。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -135,4 +135,4 @@ tag:
以上就是我对互联网从业技术人员十年成长之路的心得,希望在你困惑和关键选择的时候可以帮助到你。如果我的只言片语能够在未来的某个时间帮助到你哪怕一点,那将是我莫大的荣幸。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -204,4 +204,4 @@ Brendan GreggJay Kreps 和 Brad Traversy 三个人走的技术路线各不相
>
> 实现战略目标,就像种树一样。刚开始只是一个小根芽,树干还没有长出来;树干长出来了,枝叶才能慢慢长出来;树枝长出来,然后才能开花和结果。刚开始种树的时候,只管栽培灌溉,别老是纠结枝什么时候长出来,花什么时候开,果实什么时候结出来。纠结有什么好处呢?只要你坚持投入栽培,还怕没有枝叶花实吗?
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -107,4 +107,5 @@ tag:
人的精力是有限的,而且面对三十这个天花板,各种事件也会接连而至,在职场中学会合理安排时间并不断提升核心能力,这样才能保证自己的竞争力。
职场就像苦海无边,回首望去可能也没有岸边停泊,但是要具有换船的能力或者有个小木筏也就大差不差了。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -343,4 +343,4 @@ tag:
- [技术面试官的 9 大误区](https://zhuanlan.zhihu.com/p/51404304)
- [如何当一个好的面试官?](https://www.zhihu.com/question/26240321)
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -200,4 +200,4 @@ tag:
- 面试中的笔试和前面的笔试风格不同,面试笔试题目不太难,但是考察是冷静思考,代码优雅,没有 bug先思考清楚在写
- 在描述项目的难点的时候,不要去聊文档调研是难点,回答这部分问题更应该是技术上的难点,最后通过了什么技术解决了这个问题,这部分技术可以让面试官来更多提问以便知道自己的技术能力。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -117,4 +117,4 @@ tag:
写在最后,笔者认为在招聘途中,并不是不允许求职者包装,但是尽可能满足能筹平衡。虽然这篇文章没有完美的结尾,但是笔者提供了面试失败的各种经验。笔者最终招到了如意的小伙伴。也希望所有技术面试官早日找到符合自己产品发展的 IT 伙伴。
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -118,4 +118,4 @@ actionactionaction ,重要的事情说三遍,做技术的不可能光
最后,祝愿优秀的你能找到自己理想的工作!
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

View File

@ -162,4 +162,4 @@ Java 卷吗?毫无疑问,很卷,我个人认为开发属于没有什么门
惟愿诸君,前程似锦!
<!-- @include: @article-footer.snippet.md -->
<!-- @include: @article-footer.snippet.md -->

Some files were not shown because too many files have changed in this diff Show More