访问查询总数

时间:2018-06-28 15:53:18

标签: sql ms-access

我正在尝试总计在某一天完成24个数据输入。我有一个日期,名称和值。是的,每小时都会产生一个值。我可以在查询中这样做吗,如果可以的话,可以提示我如何获得所需的信息。

这里是数据样本。 _

TIMESTAMP   IDName  SumOf_VALUE
6/13/18 1:01 AM EFF_Flow_MGD    193479.2656
6/13/18 2:01 AM EFF_Flow_MGD    191460.9531
6/13/18 3:01 AM EFF_Flow_MGD    169738.5938
6/13/18 4:01 AM EFF_Flow_MGD    171580.0938
6/13/18 5:01 AM EFF_Flow_MGD    158367.4531
6/13/18 6:01 AM EFF_Flow_MGD    151303.2813
6/13/18 7:01 AM EFF_Flow_MGD    148457.6563
6/13/18 8:01 AM EFF_Flow_MGD    151200.3594
6/13/18 9:01 AM EFF_Flow_MGD    154745.0156
6/13/18 10:01 AM    EFF_Flow_MGD    179623.25
6/13/18 11:01 AM    EFF_Flow_MGD    193257.0938
6/13/18 12:01 PM    EFF_Flow_MGD    201511.2813
6/13/18 1:01 PM EFF_Flow_MGD    210372.8906
6/13/18 2:01 PM EFF_Flow_MGD    203826.0625
6/13/18 3:01 PM EFF_Flow_MGD    205648.4531
6/13/18 4:01 PM EFF_Flow_MGD    200690.2656
6/13/18 5:01 PM EFF_Flow_MGD    201725.4531
6/13/18 6:01 PM EFF_Flow_MGD    199851.2656
6/13/18 7:01 PM EFF_Flow_MGD    190038.3281
6/13/18 8:01 PM EFF_Flow_MGD    188712.25
6/13/18 9:01 PM EFF_Flow_MGD    197430.9531
6/13/18 10:01 PM    EFF_Flow_MGD    176996.25
6/13/18 11:01 PM    EFF_Flow_MGD    190499.0313

编辑-已尝试添加SQL(通过注释)

SELECT Sum(dbo_new_stuff1.[_VALUE]) AS SumOf_VALUE, dbo_new_stuff1.IDName, dbo_new_stuff1.[_TIMESTAMP] 
FROM dbo_new_stuff1 GROUP BY dbo_new_stuff1.IDName, dbo_new_stuff1.[_TIMESTAMP] 
HAVING (((dbo_new_stuff1.[_TIMESTAMP])>#6/12/2018 16:0:0#)) 
ORDER BY dbo_new_stuff1.[_TIMESTAMP];

1 个答案:

答案 0 :(得分:1)

我们需要将_TIMESTAMP减少为其日期部分...因此,请尝试此操作。 第一次尝试仅在SQLServer中有效,而在MSAcccess中无效。

SELECT
    CONVERT(date, dbo_new_stuff1.[_TIMESTAMP]) as justDate
    ,dbo_new_stuff1.idname
    ,Sum(dbo_new_stuff1.[_VALUE]) AS sumof_value
FROM     dbo_new_stuff1
GROUP BY dbo_new_stuff1.idname, CONVERT(date, dbo_new_stuff1.[_TIMESTAMP]) 
HAVING   (CONVERT(date, dbo_new_stuff1.[_TIMESTAMP]) >#6/12/2018#)
ORDER BY CONVERT(date, dbo_new_stuff1.[_TIMESTAMP]), dbo_new_stuff1.idname ;

感谢Thomas G纠正我提出的MSAccess解决方案-

SELECT
   Int( dbo_new_stuff1.[_TIMESTAMP]) as justDate
    ,dbo_new_stuff1.idname
    ,Sum(dbo_new_stuff1.[_VALUE]) AS sumof_value
FROM     dbo_new_stuff1
GROUP BY dbo_new_stuff1.idname, Int( dbo_new_stuff1.[_TIMESTAMP]) 
HAVING   (Int( dbo_new_stuff1.[_TIMESTAMP]) >#6/12/2018#)
ORDER BY Int( dbo_new_stuff1.[_TIMESTAMP]), dbo_new_stuff1.idname ;

哪个给出此结果-

justDate    idname          sumof_value
6/13/2018   EFF_Flow_MGD    4230515.5001