数据库中的时间区段统计问题?
基本情况:表A 有字段 Gdate(记录日期格式:2008-01-01) Gtime(记录时间格式:23:45:00) money(格式0.00)
工作时间比较特殊,跨00:00:00 每天工作周期为第一天的上午11:00 到第二天的凌晨 2:00
问题:统计一个或多个工作周期(天)的money和,该如何写SQL语句?
这样写可以吗?:
“select sum(money) where (Gdate + Gtime)>'2008-01-01 11:00:00' and (gdate + Gtime)<'2008-01-02 02:00:00'”
--------------------编程问答-------------------- 需看你时间字段的数据格式而定。如ACCESS数据库中时间字段其格式就是从 100 到 9999.年的日期与时间值 8 个字节,设置为一般日期
例:08-12-1 14:00:00
sql = "select sum(money) where 日期 BETWEEN #08-01-01 11:00:00# and #2008-01-02 02:00:00#"
你那个用法,时间字段最好包含日期和时间组合,如:2008-12-01 14:00:00,写在一个字段内
sql = "select sum(money) where 日期 >='2008-01-01 11:00:00' and 日期<= '2008-01-02 02:00:00'"
--------------------编程问答-------------------- 现在的问题是,数据库格式是固定的,不能修改,因为还有另外的软件使用这个数据库。如果日期和时间在一个字段内问题就好解决了,现在就是日期和时间在不同的字段内该如何解决? --------------------编程问答--------------------
select sum(money) where (Gdate + Gtime)>='2008-01-01 11:00:00' and (gdate + Gtime) <='2008-01-02 02:00:00'--------------------编程问答--------------------
select sum(money) where (Gdate + Gtime) between '2008-01-01 11:00:00' and '2008-01-02 02:00:00'
select sum(money) where (Gdate + Gtime)>='2008-01-01 11:00:00' and (gdate + Gtime) <='2008-01-02 02:00:00'--------------------编程问答-------------------- 用的是什么数据库? --------------------编程问答--------------------
select sum(money) where (Gdate + Gtime) between '2008-01-01 11:00:00' and '2008-01-02 02:00:00'
我的建议是:
增加一个字段,用它来保存工作日。例如,将当前时间减去 8 小时,作为工作计时(好比用格林威治时间来记录北京的工作时刻)。这样,一个工作日就都在同一日历天之中了。
rs.workingdate = Int(DateAdd("h", -8, Now()))
select sum(money) from biao group by workman, workingdate
补充:VB , 数据库(包含打印,安装,报表)