doulvyi2172
2013-02-18 11:11
浏览 89
已采纳

计算加班工时并将加班更新到表

I have table columns workhours and overtime, and I would like to do a SQL or PHP query that checks if the workinghours are over 8 hours and if so it UPDATEs the worked overtime to overtime column.

Here's my table:

id   workinghours    overtime
1,   4.79,           ---
2,   8.73,           ---
3,   7.97,           ---  

For example on the second row there is 8.73 hours of work and so it would update the 0.73 hours to the overtime column.

图片转代码服务由CSDN问答提供 功能建议

我有表列 workhours 超时,我 想做一个SQL或PHP查询来检查工作时间是否超过8小时,如果是这样, UPDATE s加班时间到加班列。

这里是 我的表:

  id workinghours overtime 
1,4.79,--- 
2,8.73,--- 
3,7.97,--- 
    
 
 

例如,在第二行有8.73小时的工作,所以它会将0.73小时更新为加班列。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • doufuxing8562 2013-02-18 11:27
    已采纳

    query :

    update work set overtime= (case when working > 8 then (working - 8) else null end);
    

    check SQL Fiddle Demo

    已采纳该答案
    打赏 评论
  • dongningce9075 2013-02-18 11:13

    Try something like this:

    update mytable
        set overtime =
            case when workinghours > 8 then workinghours - 8 else 0 end
    ;
    
    打赏 评论
  • dongzhuang6177 2013-02-18 11:28
    update YourTable 
           set overtime=workinghours-8 
               where workinghours>8
    
    打赏 评论

相关推荐 更多相似问题