• SQL计算两个时间段相隔时间


    SQL语句:

    select cast(floor(datediff(minute,时间1,时间2) / 1440) as varchar)+'天'+

           cast(floor((datediff(minute,时间1,时间2) % 1440)/60) as varchar)+'小时'+

           cast(((datediff(minute,时间1,时间2))-

               (floor(datediff(minute,时间1,时间2) / 1440) *1440)-

               (floor((datediff(minute,时间1,时间2) % 1440)/60)*60)) as varchar)+'分'

     from 表名

    返回:xx天xx小时xx分

    ----------------------------------------------------------------------------------------------------------------

    实例:

    select oc.ID,oc.CarNumber,oc.PrintTime1,oc.PrintTime2, (

     cast(floor(datediff(minute,oc.PrintTime1,oc.PrintTime2) / 1440) as varchar)+'天'+

           cast(floor((datediff(minute,oc.PrintTime1,oc.PrintTime2) % 1440)/60) as varchar)+'小时'+

           cast(((datediff(minute,oc.PrintTime1,oc.PrintTime2))-

               (floor(datediff(minute,oc.PrintTime1,oc.PrintTime2) / 1440) *1440)-

               (floor((datediff(minute,oc.PrintTime1,oc.PrintTime2) % 1440)/60)*60)) as varchar)+'分') interval
     from t_ordercar oc
    left join t_order o on oc.OrderID = o.ID
    where o.SupplierName='金冠电厂2'  and  datediff(d,o.AddTime,'2017-12-19') =0

    返回结果:

  • 相关阅读:
    LeetCode 137. Single Number II
    LeetCode 16. 3Sum Closest
    LeetCode 18. 4Sum
    LeetCode 15. 3Sum
    LeetCode 166. Fraction to Recurring Decimal
    LeetCode Anagrams
    Java: Difference between ArrayList and LinkedList
    LeetCode 242. Valid Anagram
    LeetCode 204. Count Primes
    Java Class Variable/Static Variable
  • 原文地址:https://www.cnblogs.com/weimingxin/p/8109215.html
Copyright © 2020-2023  润新知