除了从今天开始,选择所有行?

时间:2022-11-30 09:31:46

I'm selecting all rows except those from last 24hs. Instead I'd like to select those which are not from today. I'm already getting the day from a datetime column using DATE().

我选择了所有的行除了最近24hs中的行。相反,我想选择那些不是今天的。我已经从使用DATE()的datetime列中获得了这一天。

How can I change the query to do it?

如何更改查询以执行此操作?

select Date, DATE(Date) AS Day
WHERE Date < DATE_SUB(CURDATE(),INTERVAL 1 DAY)

2 个解决方案

#1


0  

OP said:

OP说:

I'd like to select those which are not from today

我想挑选今天没有的

bfavaretto's solution:

bfavaretto的解决办法:

SELECT Date, DATE(Date) AS Day
WHERE Date < CURDATE()

would answer the question:

回答这个问题:

I'd like to select those which date is before today

我想选择今天之前的日期

To properly answer OP's question this query should be run (assuming date is a datetime because of the OP's cast, I'm casting it to a date field, but the cast is unnecesary if Date is actually a date field):

要正确地回答OP的问题,这个查询应该运行(假设由于OP的强制转换,日期是datetime,我将它转换为date字段,但是如果date实际上是date字段,那么转换是不必要的):

SELECT Date, DATE(Date) AS Day FROM aTable
WHERE Date(date) != CURDATE()

#2


3  

It's easier than you think:

这比你想象的要简单:

SELECT Date, DATE(Date) AS Day
WHERE Date < CURDATE()

#1


0  

OP said:

OP说:

I'd like to select those which are not from today

我想挑选今天没有的

bfavaretto's solution:

bfavaretto的解决办法:

SELECT Date, DATE(Date) AS Day
WHERE Date < CURDATE()

would answer the question:

回答这个问题:

I'd like to select those which date is before today

我想选择今天之前的日期

To properly answer OP's question this query should be run (assuming date is a datetime because of the OP's cast, I'm casting it to a date field, but the cast is unnecesary if Date is actually a date field):

要正确地回答OP的问题,这个查询应该运行(假设由于OP的强制转换,日期是datetime,我将它转换为date字段,但是如果date实际上是date字段,那么转换是不必要的):

SELECT Date, DATE(Date) AS Day FROM aTable
WHERE Date(date) != CURDATE()

#2


3  

It's easier than you think:

这比你想象的要简单:

SELECT Date, DATE(Date) AS Day
WHERE Date < CURDATE()