dquv73115 2010-05-16 19:56
浏览 39
已采纳

计算列或存储过程还是只需要php函数?

I have an order table in MySQL database, having a field/column which stores the date timestamp of when the order was placed.

I need to calculate when the order must be shipped. I could probably figure out how to write a function to calculate the ship date and call that when ever needed but I think, not sure it may make more sense to have the shipdate as a calculated column.

That being said, I have never used a stored procedure or created a calculated field. The later I think would be best but again not sure. I used to make calculated field all the time in FMP but I've gotten away from that program.

  • 写回答

1条回答 默认 最新

  • duanliao2310 2010-05-16 19:58
    关注

    I would do it as a view. This is basically a select statement where one result column is the ship date. You can add other relevant columns too. Any app with access to the database can then access the view the same way as ordinary tables.

    If your table looked like:

    create table orders(id INTEGER PRIMARY KEY AUTO_INCREMENT,
                        order_date DATETIME);                                                                      
    

    and you always shipped 3 days after, you could use:

    create view order_view as 
      select id, 
             order_date, 
             order_date + INTERVAL 3 DAY as ship_date 
      from orders;
    

    The select statement can be made as complex as needed. Then, you just read order_view in any application, as if it were an ordinary table.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?