I have a table tbl_a, with “ID” as a primary key, with columnns “GROUP_ID”,”DATE”,”LENGTH”,”VALID”,”CID”
I’d like to make an update query that would update as:
UPDATE all GROUP_ID of 7 to be CID=9, and
if(DATE+LENGTH<TODAY) // I want to say if the DATE column with the addition of LENGTH months is smaller than today’s date(NOW()),
THEN
SET VALID to be FALSE
for that row.
using YYYY-mm-dd format
so that if the table was
ID| GROUP_ID | DATE | LENGTH| VALID| CID
---------------------------------------------------
1| 7 | 2011-12-01 | 1 | 1 | 2
2| 7 | 2012-01-01 | 1 | 1 | 7
3| 7 | 2012-02-01 | 1 | 1 | 2
4| 7 | 2012-03-01 | 2 | 1 | 3
after the update:
ID| GROUP_ID | DATE | LENGTH| VALID| CID
---------------------------------------------------
1| 7 | 2011-12-01 | 1 | 0 | 9 // res:2012-12-01,update VALID
2| 7 | 2012-01-01 | 1 | 0 | 9 // res:2012-02-01,update VALID
3| 7 | 2012-02-01 | 1 | 1 | 9 // res:2012-03-01,no update for VALID
4| 7 | 2012-03-01 | 2 | 1 | 9 // res:2012-05-01,no update for VALID
Could you please tell me the syntax for that query?
1 Answer