开发者

calculated column or stored procedure or just php function needed?

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 b开发者_如何学运维est but again not sure. I used to make calculated field all the time in FMP but I've gotten away from that program.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜