dquv73115
dquv73115
2010-05-16 19:56

计算列或存储过程还是只需要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 duanliao2310 11年前

    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.

    点赞 评论 复制链接分享