陈寅恪的子女陈美延:在ACCESS表中实现按日,月,年统计的SQL语句

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 16:35:02
订单表ORDER:
ID ProductPay(商品金额)CarryPay(运费) Type Time
-----------------------------
1 200 20 发货 2005-1-1 11:52:23
2 200 50 发货 2005-1-1 11:56:23
3 150 12 发货 2005-1-2 13:14:56
4 620 45 收货 2005-1-1 12:25:02
5 120 10 收货 2005-1-3 22:12:30
。。。

想计算每天发货和收获的金额:
Time Out(发货金额)OutCarry(发货运费)In(收货金额)InCarry(收获运费)
----------------------------------------
2005-1-1 400 70 620 45
2005-1-2 150 12 0 0
2005-1-3 0 0 120 10
。。。。
在SQL SERVER中可以这样实现:
select
Time = convert(char(10),Time,120),
out = sum(case when type = '发货' then ProductPay else 0 end),
OutCarry = sum(case when type = '发货' then CarryPay else 0 end),
in = sum(case when type = '收货' then ProductPay else 0 end),
InCarry = sum(case when type = '收货' then CarryPay else 0 end)
from
ORDER
group by
convert(char(10),Time,120)
在ACCESS中怎样实现呢?好像ACCESS不支持以上语句
我自己已经搞定了,你大家看看吧:
select COUNT(ID),DATEADD('m',-DATEDIFF('m',StartTime,Now()),Now()) from Table Group by DATEDIFF('m',StartTime,Now()) Order by COUNT(ID) desc