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.

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

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?