日期:2014-05-17  浏览次数:20986 次

关于汇总查询的问题
SQL code

订单表ctoc_order
日期字段ORDER_CREATE_TIME
金额PRODUCT_AMOUNT

查询2011-06-28到2012-05-28这段时间,每天交易总金额

SELECT  ORDER_CREATE_TIME,sum(PRODUCT_AMOUNT)
FROM ctoc_order
WHERE 1=1 
and ORDER_SUBSTATUS in(0,1)
and ORDER_CREATE_TIME between to_date('2011-06-28','yyyy-MM-dd') and to_date('2012-05-28','yyyy-MM-dd')
group by ORDER_CREATE_TIME





这样查询后的结果,每天会有多条记录,没有达到汇总的目的
记录如下:

2011-06-28 66.9
2011-06-28 66.9
2011-06-28 66.9
2011-06-29 32.5
2011-07-06 109
2011-07-06 218
不知道SQL哪里错了...

------解决方案--------------------
SQL code


订单表ctoc_order
日期字段ORDER_CREATE_TIME
金额PRODUCT_AMOUNT

查询2011-06-28到2012-05-28这段时间,每天交易总金额

SELECT  trunc(ORDER_CREATE_TIME),sum(PRODUCT_AMOUNT)
FROM ctoc_order
WHERE 1=1 
and ORDER_SUBSTATUS in(0,1)
and ORDER_CREATE_TIME between to_date('2011-06-28','yyyy-MM-dd') and to_date('2012-05-28','yyyy-MM-dd')
group by trunc(ORDER_CREATE_TIME)