2010-12-10 59 views
0

我正在查詢MySQL數據庫,並且需要在比較操作之前向列(類型爲date)添加一年。在SQL查詢中比較之前添加年份列

我希望是這個樣子:

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

回答

3

用途:

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

參考:

+1

+1。但是,只有'在哪裏'重新+間隔1年<'2009-12-12'`也應該有效 – a1ex07 2010-12-10 00:52:17