sql语句查询 日期比较_SQL查询比较日期

sql语句查询 日期比较

For comparing dates in SQL, we use the DATE() function. The date should be in the DDMMYY format. The following is the syntax for the DATE() function.

为了比较SQL中的日期,我们使用DATE()函数。 该日期应为DDMMYY格式。 以下是DATE()函数的语法。

Syntax:

句法:

    SELECT * FROM TableName WHERE ColumName=Date;

To have a better understanding of the concept we will have the following code,

为了更好地理解该概念,我们将提供以下代码,

CREATE TABLE CompDate
(
Name VARCHAR(100),
Login DATE
);

INSERT INTO CompDate VALUES('John','22042019');
INSERT INTO CompDate VALUES('Bob','12052018');
INSERT INTO CompDate VALUES('Carol','10032016');
INSERT INTO CompDate VALUES('David','08081995');

SELECT * FROM  CompDate;

Output

输出量

John|22042019
Bob|12052018
Carol|10032016
David|8081995

SELECT * FROM CompDate WHERE Login = '10032016';

Output

输出量

Carol|10032016

In the above statement, if we use the greater than sign:

在上面的语句中,如果我们使用大于号:

SELECT * FROM CompDate WHERE Login > '10032016';

Output

输出量

John|22042019
Bob|12052018

Hence, we can conclude that dates can be compared in SQL using simple statements.

因此,我们可以得出结论,可以使用简单的语句在SQL中比较日期。

翻译自: https://www.includehelp.com/sql/query-to-compare-dates.aspx

sql语句查询 日期比较

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值