SQL组合舍入与舍入十进制SQL2008

时间:2017-01-04 15:17:10

标签: c# sql asp.net sql-server

我有一张表格,其中包含我们内部开发的自定义时间表应用程序中的员工小时和分钟。我能够得到几小时的总和,我也能够舍入和分割分钟,但我只能分开这样做。我需要能够把它结合起来。在下面的2条陈述中,我正在寻找基于日期和用户时钟的特定参数。我的结果是两个单独的答案1.070000和8.0000。这个结果应该是9.07。我知道我错过了很多,但需要一些帮助,将这些结果合二为一。我该怎么做?

示例:

select (SUM(hrs)) as Total_Hrs 
from dbo.TLA_Totals 
WHERE event_name like '%Clock%' AND dte_dd = 01 and dte_ddd = 'Sun' 
and dte_mm = 01 and dte_yyyy = 2017

select ROUND(SUM(mins) / 60.0, 2) as Total_Minutes 
from TLA_Totals 
where dte_dd = 01 and dte_mm = 01

2 个答案:

答案 0 :(得分:0)

我有点困惑,但您可以尝试通过执行这两个查询来连接这两个查询,然后将两个值一起添加 - 也可以使用WITH语句

    SELECT Q1.Total_Hrs  + CA.Total_Minutes AS Grand_Total FROM  (select (SUM(hrs)) as Total_Hrs 
from dbo.TLA_Totals 
WHERE event_name like '%Clock%' AND dte_dd = 01 and dte_ddd = 'Sun' 
and dte_mm = 01 and dte_yyyy = 2017) Q1
CROSS APPLY (
select ROUND(SUM(mins) / 60.0, 2) as Total_Minutes 
from TLA_Totals 
where dte_dd = 01 and dte_mm = 01) CA

答案 1 :(得分:0)

或许这样的事情?

select TotalTime = sum(Total_Hrs)
from
(
    select (SUM(hrs)) as Total_Hrs 
    from dbo.TLA_Totals 
    WHERE event_name like '%Clock%' AND dte_dd = 01 and dte_ddd = 'Sun' 
    and dte_mm = 01 and dte_yyyy = 2017

    UNION ALL

    select ROUND(SUM(mins) / 60.0, 2) as Total_Minutes 
    from TLA_Totals 
    where dte_dd = 01 and dte_mm = 01
) x