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 op开发者_开发问答eration.
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:
- DATE_ADD
You can use the mysql DATE_ADD function:
DATE_ADD(renewed, INTERVAL 1 YEAR)
精彩评论