开发者

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜