当前位置:网站首页>Five SQL functions for operation date that must be known in SQL tutorial

Five SQL functions for operation date that must be known in SQL tutorial

2022-06-23 10:08:00 Knowledge fatness

If you ask about the most important skills of a data scientist before I get my first job , My answer must be Python. without doubt !

I am now a data scientist , If you ask me the same question , My answer is still Python. however , I have a second thought . What makes me think twice is SQL.

SQL It is a necessary skill for data scientists . It is mainly used to query relational databases , But it can do more .SQL Equipped with so many functions , Make it an efficient data analysis and operation tool .

In this paper , We will introduce 5 For operation date SQL function . When processing data involving date or time-based information , They will come in handy .

Be careful : SQL Used by many relational database management systems , for example MySQL、SQL Server、PostgreSQL etc. . Although most of them use the same SQL grammar , But there may be subtle differences . In this paper , We will use SQL Server.

1. Get date

seeing the name of a thing one thinks of its function ,getdate Function gives us today's date . Let's take an example .

DECLARE @mydate Date
SET @mydate = GETDATE()
print @mydate
'2021-08-22'

Let's create a name “mydate” And specify its value as today's date .

2. Add date

The name of this function is more self explanatory than the previous one .dateadd Function to add a time or date interval to the date .

As usual , Syntax is easier to understand through examples .

DECLARE @mydate Date
SET @mydate = GETDATE()
SELECT DATEADD(MONTH, 1, @mydate) AS NextMonth
NextMonth
2021-09-22
</
原网站

版权声明
本文为[Knowledge fatness]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230952313822.html