当前位置:网站首页>SQL教程之 5 个必须知道的用于操作日期的 SQL 函数
SQL教程之 5 个必须知道的用于操作日期的 SQL 函数
2022-06-23 09:52:00 【知识大胖】
如果你在我得到第一份工作之前问到数据科学家最重要的技能,我的答案肯定是 Python。毫无疑问!
我现在是一名数据科学家,如果你问我同样的问题,我的答案仍然是 Python。不过,我有第二个想法。让我三思而后行的是 SQL。
SQL 是数据科学家必备的技能。它主要用于查询关系数据库,但它能够执行更多。SQL 配备了如此多的功能,使其成为高效的数据分析和操作工具。
在本文中,我们将介绍 5 个用于操作日期的 SQL 函数。在处理涉及基于日期或时间的信息的数据时,它们会派上用场。
注意: SQL 被许多关系数据库管理系统使用,例如 MySQL、SQL Server、PostgreSQL 等。尽管它们大多采用相同的 SQL 语法,但可能存在细微差别。在本文中,我们将使用 SQL Server。
1.获取日期
顾名思义,getdate 函数为我们提供了今天的日期。让我们做一个例子。
DECLARE @mydate Date
SET @mydate = GETDATE()
print @mydate
'2021-08-22'
我们创建一个名为“mydate”的变量并将其值指定为今天的日期。
2. 添加日期
这个函数的名称比前一个更不言自明。dateadd 函数用于将时间或日期间隔添加到日期。
与往常一样,通过示例更容易理解语法。
DECLARE @mydate Date
SET @mydate = GETDATE()
SELECT DATEADD(MONTH, 1, @mydate) AS NextMonth
NextMonth
2021-09-22
</边栏推荐
- RT-Thread 添加 msh 命令
- 漫画 | Code Review快把我逼疯了!
- 【CTF】bjdctf_2020_babyrop
- Successful experience in postgraduate entrance examination for MTI master of English translation major of Beijing University of science and technology in 2023
- 2022 gdevops global agile operation and maintenance summit - essence playback of Guangzhou station (with PPT download)
- [SUCTF 2019]CheckIn
- mysql中innodb下的redo log什么时候开始执行check point落盘的?
- Pizza ordering design - simple factory model
- Difference between global shutter and roller shutter
- RGB and CMYK color modes
猜你喜欢

RPC kernel details you must know (worth collecting)!!!

Jog sport mode

Shengshihaotong enables high-quality development with industrial Digitalization

Liujinhai, architect of zhongang Mining: lithium battery opens up a Xintiandi for fluorine chemical industry

Dr. Sun Jian was commemorated at the CVPR conference. The best student thesis was awarded to Tongji Ali. Lifeifei won the huangxutao Memorial Award

开发者,你对云计算可能有些误解

薄膜干涉数据处理

Go 单元测试
![[SUCTF 2019]CheckIn](/img/0e/75bb14e7a3e55ddc5126581a663bfb.png)
[SUCTF 2019]CheckIn

陆奇首次出手投资量子计算
随机推荐
How should junior programmers who enter a small company improve themselves?
Go language JSON processing
Bioinformatics | 基于相互作用神经网络的有效药物-靶标关联预测
[CISCN2019 华北赛区 Day2 Web1]Hack World
2022 gdevops global agile operation and maintenance summit - essence playback of Guangzhou station (with PPT download)
Copilot免费时代结束!正式版67元/月,学生党和热门开源项目维护者可白嫖
Bi SQL drop & alter
STM32F1与STM32CubeIDE编程实例-红外寻迹传感器驱动
太阳塔科技招聘PostgreSQL数据库工程师
I have been promoted. How can I get along with my former colleagues at the same level?
NiO example
Pizza ordering design - simple factory model
Servlet-02 lifecycle
Form repeated submission problem
Three implementation methods of distributed lock
Use Base64 to show pictures
regular expression
JSP getting started summary
High performance computing center Infiniband overview
基於STM32設計的寵物投喂器