开发者

Changing date to days with update statement in Mysql

I have a table that lists Dates as 110427 in Date col. I Have a days col, which is days form today.

This sql gets all my dates:

 SELECT DISTINCT date FROM test.op;

This Sql gets days from today:

SELECT TO_DAYS('20110430') -  TO_DAYS(NOW());

How do I loop an update? Where result would

     Date    Days
    110430   3
    110530   33

Would use an if or case? 开发者_StackOverflow社区


How about this?

UPDATE   MyTable
SET      Days = TO_DAYS(date) - TO_DAYS(NOW());

This would update each row's Days column to have the value from the the row's date column run through your subtraction.


UPDATE test.op SET days = TO_DAYS(date) - TO_DAYS(NOW());

This will set the days column with the difference between the date and now for all records in the table test.op. Adjust for your exact schema.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜