在SQL查询中比较之前添加年份到列。

时间:2022-11-27 07:52:42

I am querying a MySQL database and I need to add a year to a column (of type date) before the compare operation.

我正在查询一个MySQL数据库,需要在执行比较操作之前向列(类型为date)添加一年。

I would expect is to look something like this:

我想大概是这样的:

SELECT count(*) AS count 
  FROM users 
 WHERE renewed + 1 year < '2009-12-12'

2 个解决方案

#1


3  

Use:

使用:

SELECT COUNT(*) AS count 
  FROM USERS u 
 WHERE DATE_ADD(u.renewed, INTERVAL 1 YEAR) < '2009-12-12'

Reference:

参考:

#2


1  

You can use the mysql DATE_ADD function:

可以使用mysql DATE_ADD函数:

DATE_ADD(renewed, INTERVAL 1 YEAR)

#1


3  

Use:

使用:

SELECT COUNT(*) AS count 
  FROM USERS u 
 WHERE DATE_ADD(u.renewed, INTERVAL 1 YEAR) < '2009-12-12'

Reference:

参考:

#2


1  

You can use the mysql DATE_ADD function:

可以使用mysql DATE_ADD函数:

DATE_ADD(renewed, INTERVAL 1 YEAR)