gpt4 book ai didi

php - 总和 :two different time query

转载 作者:行者123 更新时间:2023-11-30 21:42:42 25 4
gpt4 key购买 nike

我用字段 'buy_datetime'sell_datetime 设置了我的 MySQL 数据库。我想以小时为单位获得不同日期时间的总时间结果。格式:'1000-01-01 00:00:00'.

例如,

  1. buy_datetime - sell_datetime = 1result
  2. buy_datetime - sell_datetime = 2result

输出总小时数 = 1resul + 2result

    public function firstHourHoldingTime(){

$count_firsthour_holding_time = DB::table('finaltrade')
->select(DB::raw('finaltrade.*'))
->sum(TIMEDIFF(Hour,"buy_datetime", "sell_datetime"))
->get();
}

最佳答案

您需要原始表达式来总结列之间的每小时差异

public function firstHourHoldingTime(){

$count_firsthour_holding_time = DB::table('finaltrade')
->select(DB::raw('SUM(TIMESTAMPDIFF(HOUR,buy_datetime, sell_datetime)) as total'))
->get();
}

关于php - 总和 :two different time query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50853580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com