我有数据库表,如:
id create_date update_date
1 2014-09-03 00:00:00 0000-00-00 00:00:00
2 2014-09-01 00:00:00 0000-00-00 00:00:00
3 2014-09-01 00:00:00 2014-09-02 00:00:00
4 2014-09-02 00:00:00 0000-00-00 00:00:00
如何设置" update_date"作为" create_date" if it 0000-00-00 00:00:00?
是:
id create_date update_date
1 2014-09-03 00:00:00 2014-09-03 00:00:00
2 2014-09-01 00:00:00 2014-09-01 00:00:00
3 2014-09-01 00:00:00 2014-09-02 00:00:00 <- not changed
4 2014-09-02 00:00:00 2014-09-02 00:00:00
感谢,
答案 0 :(得分:1)
尝试以下查询
UPDATE table
SET update_date=create_date
where UNIX_TIMESTAMP(update_date) = 0;
答案 1 :(得分:0)
update TABLE set update_date=create_date where update_date='0000-00-00 00:00:00';