简体   繁体   中英

Add year to column before compare in SQL query

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

I would expect is to look something like this:

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

Use:

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

Reference:

您可以使用mysql DATE_ADD函数

DATE_ADD(renewed, INTERVAL 1 YEAR)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM