时间序列中的6大类10种异常值处理方法(从根源上提高预测精度)

 

一、本文介绍

本文介绍的内容是在时间序列中异常值处理的方法,当我进行时间序列分析建模收集数据的过程中,往往都存在着一些特数据情况导致数据中存在着一些异常值,这些异常值往往会导致模型识别到不正常的模式从而无法准确的预测, (我试验过一个数据集清楚之后MAE的精度甚至能提升0.1左右),所以对于异常值的检测和处理对于时间序列来说是十分重要的,本篇文章需要配合我的另一篇文章配合阅读,另一篇文章介绍了如何进行异常值检测所以本文篇文章下面来介绍当我们检测出异常值之后如何进行异常值处理。

前文回顾:时间序列预测:深度学习、机器学习、融合模型、创新模型实战案例

目录

一、本文介绍

 二、异常值处理的方法

三、数据集介绍 

四、异常值处理

4.1 删除法

4.2 替换法 

4.2.1 平均值替换

4.2.2 中位数替换

4.2.3 众数替换

4.2.4 移动平滑替换

4.3 变换法

4.3.1 Box-Cox变化

4.3.2 对数变化

4.4 分箱法 

4.5 使用机器学习模型 

4.6 基于规则的方法 

五、全文总结


 二、异常值处理的方法

处理异常值,主要有以下几种方法:

  1. 删除法:直接删除含有异常值的数据。这种方法简单直接,但可能会丢失其他有用信息。

  2. 替换法

    • 平均值替换:用整个数据集的平均值替换异常值。
    • 中位数替换:用中位数来替换异常值,尤其适用于数据不对称分布的情况。
    • 众数替换:对于分类数据,可以使用众数来替换异常值。
    • 平滑窗口替换:用异常值附近的平均值替换,需要设定一个窗口大小
  3. 变换法

    • 对数变换:适用于右偏数据,可以减少数据的偏斜。
    • Box-Cox变换:一种通用的转换方法,可以处理各种类型的偏态分布。
  4. 分箱法:将数据分成几个区间(箱子),然后用箱子的边界值或中值来替换异常值。

  5. 使用机器学习模型:通过构建模型预测异常值并替换。这种方法通常在数据量较大且复杂时使用。

  6. 基于规则的方法:根据领域知识或特定规则来确定和处理异常值。

总结:选择哪种方法取决于异常值的性质和分析的目标。在某些情况下,结合使用多种方法可能会更有效。例如,可以先通过替换或修正方法处理异常值,然后使用变换或鲁棒性较强的模型进行分析。重要的是要理解异常值的来源和它们对分析结果可能产生的影响,从而做出恰当的处理。

三、数据集介绍 

我们本文用到的数据集是官方的ETTh1.csv ,数据集是一个用于时间序列预测的电力负荷数据集,它是 ETTh 数据集系列中的一个。ETTh 数据集系列通常用于测试和评估时间序列预测模型。以下是 ETTh1.csv 数据集的一些内容:

数据内容:该数据集通常包含有关电力系统的多种变量,如电力负荷、天气情况等。这些变量可以用于预测未来的电力需求或价格。

时间范围和分辨率:数据通常按小时或天记录,涵盖了数月或数年的时间跨度。具体的时间范围和分辨率可能会根据数据集的版本而异。 

以下是该数据集的部分截图->

 

四、异常值处理

4.1 删除法

删除法:直接删除含有异常值的数据。这种方法简单直接,但可能会丢失其他有用信息。

推荐指数:

import pandas as pd
from scipy.stats import zscore
import matplotlib.pyplot as plt

# Load the data
file_path = 'ETTh1.csv'  # Replace with your file path
data = pd.read_csv(file_path)

# Calculate Z-Scores for the 'OT' column
data['OT_ZScore'] = zscore(data['OT'])

# Filter out rows where the Z-Score is greater than 2
outliers_removed = data[data['OT_ZScore'].abs() <= 2]

# Creating a figure with two subplots
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(15, 6))

# Plotting the original data in the first subplot
axes[0].plot(data['OT'], label='Original Data', color='blue', alpha=0.7)
axes[0].set_title('Original "OT" Data')
axes[0].set_xlabel('Index')
axes[0].set_ylabel('OT Values')
axes[0].grid(True)

# Plotting the cleaned data in the second subplot
axes[1].plot(outliers_removed['OT'].reset_index(drop=True), label='Data After Removing Outliers', color='green', alpha=0.7)
axes[1].set_title('Cleaned "OT" Data')
axes[1].set_xlabel('Index')
axes[1].set_ylabel('OT Values')
axes[1].grid(True)

# Adjusting layout and displaying the plot
plt.tight_layout()
plt.show()

可以明显的看到当我们使用将异常值删除之后我们的数据范围从(40,-5)来到了(30,-5)数据范围变得更窄,起到了一定数据平缓的作用,让数据的波动性变小从而提高模型的预测精度(当然在实际中及其不推荐使用这种方法,因为这会破坏数据的周期性)

 

4.2 替换法 

4.2.1 平均值替换

平均值替换:用整个数据集的平均值替换异常值。

推荐指数:⭐⭐⭐

import pandas as pd
from scipy.stats import zscore
import matplotlib.pyplot as plt

# Load the data
file_path = 'ETTh1.csv'  # Replace with your file path
data = pd.read_csv(file_path)

# Calculate Z-Scores for the 'OT' column
data['OT_ZScore'] = zscore(data['OT'])

# Filter out rows where the Z-Score is greater than 2
outliers_removed = data[data['OT_ZScore'].abs() <= 2]

# Creating a figure with two subplots
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(15, 6))

# Plotting the original data in the first subplot
axes[0].plot(data['OT'], label='Original Data', color='blue', alpha=0.7)
axes[0].set_title('Original "OT" Data')
axes[0].set_xlabel('Index')
axes[0].set_ylabel('OT Values')
axes[0].grid(True)

# Plotting the cleaned data in the second subplot
axes[1].plot(outliers_removed['OT'].reset_index(drop=True), label='Mean Value Replacement', color='green', alpha=0.7)
axes[1].set_title('Cleaned "OT" Data')
axes[1].set_xlabel('Index')
axes[1].set_ylabel('OT Values')
axes[1].grid(True)

# Adjusting layout and displaying the plot
plt.tight_layout()
plt.show()

可以看到这种方法的效果和上面的删除差多,在实际使用中平均值使用替换可以算做一种保守的方法。 

4.2.2 中位数替换

中位数替换用中位数来替换异常值,尤其适用于数据不对称分布的情况。

推荐指数:⭐⭐⭐⭐

import pandas as pd
from scipy.stats import zscore
import matplotlib.pyplot as plt

# Load the data
file_path = 'ETTh1.csv'  # Replace with your file path
data = pd.read_csv(file_path)

# Calculate Z-Scores for the 'OT' column
data['OT_ZScore'] = zscore(data['OT'])

# Filter out rows where the Z-Score is greater than 2
outliers_removed = data[data['OT_ZScore'].abs() <= 2]

# Creating a figure with two subplots
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(15, 6))

# Plotting the original data in the first subplot
axes[0].plot(data['OT'], label='Original Data', color='blue', alpha=0.7)
axes[0].set_title('Original "OT" Data')
axes[0].set_xlabel('Index')
axes[0].set_ylabel('OT Values')
axes[0].grid(True)

# Plotting the cleaned data in the second subplot
axes[1].plot(outliers_removed['OT'].reset_index(drop=True), label='Median Value Replacement', color='green', alpha=0.7)
axes[1].set_title('Cleaned "OT" Data')
axes[1].set_xlabel('Index')
axes[1].set_ylabel('OT Values')
axes[1].grid(True)

# Adjusting layout and displaying the plot
plt.tight_layout()
plt.show()

大家由这两张图片可以看出替换法的效果都差不多。 

4.2.3 众数替换

众数替换:对于分类数据,可以使用众数来替换异常值。

推荐指数:⭐⭐⭐⭐

import pandas as pd
from scipy.stats import zscore
import matplotlib.pyplot as plt

# Load the data
file_path = 'ETTh1.csv'  # Replace with your file path
data = pd.read_csv(file_path)

# Calculate Z-Scores for the 'OT' column
data['OT_ZScore'] = zscore(data['OT'])

# Filter out rows where the Z-Score is greater than 2
outliers_removed = data[data['OT_ZScore'].abs() <= 2]

# Creating a figure with two subplots
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(15, 6))

# Plotting the original data in the first subplot
axes[0].plot(data['OT'], label='Original Data', color='blue', alpha=0.7)
axes[0].set_title('Original "OT" Data')
axes[0].set_xlabel('Index')
axes[0].set_ylabel('OT Values')
axes[0].grid(True)

# Plotting the cleaned data in the second subplot
axes[1].plot(outliers_removed['OT'].reset_index(drop=True), label='Mode Value Replacement', color='green', alpha=0.7)
axes[1].set_title('Cleaned "OT" Data')
axes[1].set_xlabel('Index')
axes[1].set_ylabel('OT Values')
axes[1].grid(True)

# Adjusting layout and displaying the plot
plt.tight_layout()
plt.show()

4.2.4 移动平滑替换

移动平滑替换:用异常值附近的平均值替换,需要设定一个窗口大小

推荐指数:⭐⭐⭐⭐⭐

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import zscore

# Load the data
file_path = 'your_file_path_here.csv'  # Replace with your file path
data = pd.read_csv(file_path)

# Calculate Z-Scores for the 'OT' column
data['OT_ZScore'] = zscore(data['OT'])

# Setting a default window size for rolling mean
window_size = 5

# Calculate the rolling mean
rolling_mean = data['OT'].rolling(window=window_size, center=True).mean()

# Replace outliers (Z-Score > 2) with the rolling mean
data['OT_RollingMean'] = data.apply(lambda row: rolling_mean[row.name] if abs(row['OT_ZScore']) > 2 else row['OT'], axis=1)

# Creating a figure with two subplots
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(15, 6))

# Plotting the original data in the first subplot
axes[0].plot(data['OT'], label='Original Data', color='blue', alpha=0.7)
axes[0].set_title('Original "OT" Data')
axes[0].set_xlabel('Index')
axes[0].set_ylabel('OT Values')
axes[0].grid(True)

# Plotting the data after replacing outliers with rolling mean in the second subplot
axes[1].plot(data['OT_RollingMean'], label='Data After Rolling Mean Replacement', color='green', alpha=0.7)
axes[1].set_title('Data After Rolling Mean Replacement of Outliers')
axes[1].set_xlabel('Index')
axes[1].set_ylabel('OT Values')
axes[1].grid(True)

# Adjusting layout and displaying the plot
plt.tight_layout()
plt.show()

 

4.3 变换法

4.3.1 Box-Cox变化

Box-Cox变换一种通用的转换方法,可以处理各种类型的偏态分布。

推荐指数:⭐⭐⭐

大家再用这种方法的时候需要注意数据中不能包含负值

import pandas as pd
from scipy.stats import zscore, boxcox
import matplotlib.pyplot as plt

# Load the data
file_path = 'ETTh1.csv'  # Replace with your file path
data = pd.read_csv(file_path)

# Calculate Z-Scores for the 'OT' column
data['OT_ZScore'] = zscore(data['OT'])

# Filter out rows where the Z-Score is greater than 2
outliers_removed = data[data['OT_ZScore'].abs() <= 2]

# Applying Box-Cox transformation
data['OT_BoxCox'], _ = boxcox(data['OT'])

# Creating a figure with two subplots
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(15, 6))

# Plotting the original data in the first subplot
axes[0].plot(data['OT'], label='Original Data', color='blue', alpha=0.7)
axes[0].set_title('Original "OT" Data')
axes[0].set_xlabel('Index')
axes[0].set_ylabel('OT Values')
axes[0].grid(True)

# Plotting the Box-Cox transformed data in the second subplot
axes[1].plot(data['OT_BoxCox'], label='Box-Cox Transformed Data', color='green', alpha=0.7)
axes[1].set_title('Box-Cox Transformed "OT" Data')
axes[1].set_xlabel('Index')
axes[1].set_ylabel('Transformed OT Values')
axes[1].grid(True)

# Adjusting layout and displaying the plot
plt.tight_layout()
plt.show()

 

4.3.2 对数变化

对数变换适用于右偏数据,可以减少数据的偏斜。

推荐指数:

这个方法同理也不能输入负数,同时这个方法在我们输入到模型之后,输出结果之后还要将结果转换回来,实际是不推荐大家使用的。

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

# Load the data
file_path = 'ETTh1.csv'  # Replace with your file path
data = pd.read_csv(file_path)

# Replace values in 'OT' column that are less than 0 with the mean of the column
ot_mean = data['OT'].mean()
data['OT'] = data['OT'].apply(lambda x: ot_mean if x < 0 else x)

# Applying logarithmic transformation
data['OT_Log'] = np.log(data['OT'])

# Creating a figure with two subplots
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(15, 6))

# Plotting the original data in the first subplot
axes[0].plot(data['OT'], label='Original Data', color='blue', alpha=0.7)
axes[0].set_title('Original "OT" Data')
axes[0].set_xlabel('Index')
axes[0].set_ylabel('OT Values')
axes[0].grid(True)

# Plotting the logarithmically transformed data in the second subplot
axes[1].plot(data['OT_Log'], label='Logarithmically Transformed Data', color='green', alpha=0.7)
axes[1].set_title('Logarithmically Transformed "OT" Data')
axes[1].set_xlabel('Index')
axes[1].set_ylabel('Transformed OT Values')
axes[1].grid(True)

# Adjusting layout and displaying the plot
plt.tight_layout()
plt.show()

 

 

4.4 分箱法 

分箱法:将数据分成几个区间(箱子),然后用箱子的边界值或中值来替换异常值。

推荐指数:⭐⭐⭐

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import zscore

# Load the data
file_path = 'your_file_path_here.csv'  # Replace with your file path
data = pd.read_csv(file_path)

# Calculate Z-Scores for the 'OT' column
data['OT_ZScore'] = zscore(data['OT'])

# Performing equal-width binning
num_bins = 10
data['OT_Binned'] = pd.cut(data['OT'], bins=num_bins)

# Calculating the median of each bin
binned_median = data.groupby('OT_Binned')['OT'].median()

# Replacing outliers with the median of the corresponding bin
data['OT_Replaced'] = data['OT'].copy()  # Creating a copy of the 'OT' column for replacements
for bin_interval, median_value in binned_median.items():
    # Find indices of outliers in this bin
    indices = data[(data['OT_Binned'] == bin_interval) & (data['OT_ZScore'].abs() > 2)].index
    # Replace these outliers with the median value of the bin
    data.loc[indices, 'OT_Replaced'] = median_value

# Creating a figure with two subplots
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(15, 6))

# Plotting the original data in the first subplot
axes[0].plot(data['OT'], label='Original Data', color='blue', alpha=0.7)
axes[0].set_title('Original "OT" Data')
axes[0].set_xlabel('Index')
axes[0].set_ylabel('OT Values')
axes[0].grid(True)

# Plotting the data after replacing outliers in the second subplot
axes[1].plot(data['OT_Replaced'], label='Data After Replacing Outliers', color='green', alpha=0.7)
axes[1].set_title('Data After Replacing Outliers with Bin Medians')
axes[1].set_xlabel('Index')
axes[1].set_ylabel('OT Values')
axes[1].grid(True)

# Adjusting layout and displaying the plot
plt.tight_layout()
plt.show()

 

4.5 使用机器学习模型 

这种方法暂时不给大家介绍了,因为这就是时间序列预测,通过预测值来替换这个值,所以想用这种方法可以看我专栏里的其它内容。 

推荐指数:⭐⭐

 

4.6 基于规则的方法 

这种方法就是需要你有特定的知识,当我们用异常值检测方法检测出异常值之后去手动修改文件,其实这种是最合理的但是需要费时。

推荐指数:⭐⭐⭐⭐

 

五、全文总结

到此本文已经全部讲解完成了,希望能够帮助到大家,在这里也给大家推荐一些我其它的博客的时间序列实战案例讲解,其中有数据分析的讲解就是我前面提到的如何设置参数的分析博客,最后希望大家订阅我的专栏,本专栏均分文章均分98,并且免费阅读。

专栏回顾->时间序列预测专栏——包含上百种时间序列模型带你从入门到精通时间序列预测

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/173903.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

每日一题(LeetCode)----数组--螺旋矩阵(一)

每日一题(LeetCode)----数组–螺旋矩阵&#xff08;一&#xff09; 1.题目&#xff08;54. 螺旋矩阵&#xff09; 给你一个 m 行 n 列的矩阵 matrix &#xff0c;请按照 顺时针螺旋顺序 &#xff0c;返回矩阵中的所有元素。 示例 1&#xff1a; 输入&#xff1a;matrix [[1…

Springboot+vue的社区医院管理系统(有报告),Javaee项目,springboot vue前后端分离项目

演示视频&#xff1a; Springbootvue的社区医院管理系统(有报告)&#xff0c;Javaee项目&#xff0c;springboot vue前后端分离项目 项目介绍&#xff1a; 本文设计了一个基于Springbootvue的前后端分离的应急物资管理系统&#xff0c;采用M&#xff08;model&#xff09;V&am…

JavaApp自动化测试系列[v1.0.0][四种等待方式]

四种等待 隐式等待&#xff1a;是在尝试发现某个元素的时候&#xff0c;如果没能立刻发现&#xff0c;就等待固定长度的时间。默认设置是0秒。一旦设置了隐式等待时间&#xff0c;它的作用范围就是Webdriver对象实例的整个生命周期显示等待&#xff1a;定义了等待条件&#xf…

Python (十二) 文件

程序员的公众号&#xff1a;源1024&#xff0c;获取更多资料&#xff0c;无加密无套路&#xff01; 最近整理了一份大厂面试资料《史上最全大厂面试题》&#xff0c;Springboot、微服务、算法、数据结构、Zookeeper、Mybatis、Dubbo、linux、Kafka、Elasticsearch、数据库等等 …

chrome内置路径合集

设置黑夜模式&#xff1a; 输入网址&#xff1a;chrome://flags/ 搜索dark 改为enable 实验项目路径 chrome://flags/ 可用来启用或者关闭某些 Chrome 的实验功能 chrome://settings 将快速打开 Chrome 浏览器的设置页面&#xff0c;页面的内容分类划分为基础和高级设置选项 …

JOSEF 静态中间继电器 ZJY-420 DC220V 板前接线,带底座 增加触点

系列型号&#xff1a; ZJY-400中间继电器&#xff1b;ZJY-600中间继电器&#xff1b; ZJY-800中间继电器&#xff1b;ZJY-020中间继电器&#xff1b; ZJY-040中间继电器&#xff1b;ZJY-060中间继电器&#xff1b; ZJY-006中间继电器&#xff1b;ZJY-008中间继电器&#xff1b;…

GitHub 2023报告-开源和AI的现状

GitHub 2023报告-开源和AI的现状 深入探讨人工智能如何与开源互动&#xff0c;以及未来几年可能出现的趋势。 背景介绍 2023年&#xff0c;开源已成为全球软件开发的标准。无论是大公司还是小团队&#xff0c;都广泛使用开源技术进行项目开发。此外&#xff0c;随着机器学习和…

Notion AI会员订阅付费

一、Notion AI优势&#xff1a; 自动化任务&#xff1a;NotionAI可以自动完成一些重复性任务&#xff0c;例如对内容进行分类和标记&#xff0c;从而提高工作效率和减少人力成本。个性化建议&#xff1a;NotionAI可以根据用户的偏好和行为模式提供个性化的建议和推荐&#xff…

编译器优化代码研究

《Effective C》条款21&#xff1a; /** * 结论&#xff1a;对自定义类型对象表达式objA*objB objC; * 定义friend MyInt operator*(const MyInt& lhs,const MyInt& rhs) * 编译器优化后&#xff1a;operator*()函数内直接在调用接收处构造(此处的匿名临时对象)&am…

2023年以就业为目的学习Java还有必要吗?

文章目录 1活力四射的 Java2从零开始学会 Java3talk is cheap, show me the code4结语写作末尾 现在学 Java 找工作还有优势吗&#xff1f; 在某乎上可以看到大家对此问题的热议&#xff1a;“2023年以就业为目的学习Java还有必要吗&#xff1f;” 。有人说市场饱和&#xff0c…

VMware——WindowServer2012R2环境安装mysql5.7.14解压版_主从复制(图解版)

目录 一、服务器信息二、192.168.132.33主服务器上安装mysql&#xff08;主&#xff09;2.1、环境变量配置2.2、安装2.2.1、修改配置文件内容2.2.2、初始化mysql并指定超级用户密码2.2.3、安装mysql服务2.2.4、启动mysql服务2.2.5、登录用户管理及密码修改2.2.6、开启远程访问 …

HP惠普暗影精灵7Plus笔记本OMEN 17.3英寸游戏本17-ck0000恢复原厂Windows11预装OEM系统

链接&#xff1a;https://pan.baidu.com/s/1ukMXI2V3D0c-kVmIQSkbYQ?pwd2rbr 提取码&#xff1a;2rbr hp暗影7P原厂WIN11系统适用型号&#xff1a; 17-ck0056TX&#xff0c; 17-ck0055TX&#xff0c; 17-ck0054TX &#xff0c;17-ck0059TX 自带所有驱动、出厂时主题壁纸、…

数据湖的概念、发展背景和价值

数据湖是一个集中化的存储系统&#xff0c;旨在以低成本、大容量的方式&#xff0c;无需预先对数据进行结构化处理&#xff0c;存储各种结构化和非结构化数据。以下是数据湖概念、发展背景和价值的详细介绍。 数据湖概念 数据湖的概念源自于对传统数据仓库的补充。传统数据仓…

git常常用命令

这篇文章中&#xff0c;一些简单的&#xff0c;大家都知道的git 命令我就不再赘述&#xff0c;我只写出来最近在项目中常用到的一些命令。这些命令可以帮助我更好的开发。 git stash 请大家设想下面的场景&#xff0c;你的本地有两个分支&#xff0c;develop,fix分支&#xf…

java创建指定分辨率的图片或修改图片的分辨率(DPI)

因为java默认的图片像素分辨率DPI72&#xff0c;分辨率有点低。所以研究了一下如何创建指定DPI的方案。 DPI&#xff1a; 指的是每英尺的像素点(dots per inch) JPEG图片 JPEG图片的元数据定义参看oracle官网。 https://docs.oracle.com/javase/8/docs/api/javax/imageio/me…

关于“计算机中由于找不到msvcr120.dll,无法继续执行代码5种解决方法

今天&#xff0c;我想和大家分享一下关于“由于找不到msvcr120.dll,无法继续执行代码5种解决方法”的话题。在我们日常的使用中&#xff0c;有时候会遇到这样的问题&#xff1a;在运行某个程序时&#xff0c;突然提示“无法继续执行代码&#xff0c;因为找不到msvcr120.dll”。…

七天.NET 8操作SQLite入门到实战 - 第二天 在 Windows 上配置 SQLite环境

前言 SQLite的一个重要的特性是零配置的、无需服务器&#xff0c;这意味着不需要复杂的安装或管理。它跟微软的Access差不多&#xff0c;只是一个.db格式的文件。但是与Access不同的是&#xff0c;它不需要安装任何软件&#xff0c;非常轻巧。 七天.NET 8操作SQLite入门到实战…

Web功能测试有哪些常用方法?

检验方法 1页面链接检查每一个链接是否都有对应的页面&#xff0c;并且页面之间切换正确&#xff1b; 2相关性检查删除/增加一项会不会对其他项产生影响&#xff0c;如果产生影响&#xff0c;这些影响是否都正确。 3检查按钮的功能是否正确如update, cancel, delete, save等…

python3函数

1、定义函数 函数代码块以def关键词开头&#xff0c;后接函数标识符名称和圆括号任何传入参数和自变量必须放在圆括号中间&#xff0c;圆括号之间可以用于定义参数函数内容以冒号&#xff1a;起始&#xff0c;并且缩进return【表达式】结束函数&#xff0c;选择性返回一个值调…

MySQL之BETWEEN AND包含范围查询总结

一、时间范围 查询参数格式与数据库类型相对应时&#xff0c;between and包含头尾&#xff0c;否则依情况 当数据库字段中存储的是yyyy-MM-dd格式&#xff0c;即date类型&#xff1a; 用between and查询&#xff0c; 参数yyyy-MM-dd格式时&#xff0c;包含头尾&#xff0c;相当…