我的数据库是Orcale , 数据表的格式是这样的。。
dateteme shuliang shuliang2
2014-06-01 00:39:00 1 1
2014-06-01 10:39:00 2 15
2014-06-01 11:39:00 3 10
2014-06-02 12:39:00 4 11
2014-06-03 13:39:00 5 13
2014-06-04 14:39:00 6 14
然后我 统计每天的数据
datetime shuliang
2014-06-01 32
2014-06-02 15
2014-06-03 18
2014-06-04 20
肯定大家帮帮忙啦。
------解决方案--------------------
这是SQL server专区,所以我用SQL Server的语法给你写:
----------------------------------------------------------------
-- Author :DBA_HuangZJ(发粪涂墙)
-- Date :2014-06-30 15:30:50
-- Version:
-- Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64)
-- Jun 28 2012 08:36:30
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([dateteme] datetime,[shuliang] int,[shuliang2] int)
insert [huang]
select '2014-06-01 00:39:00',1,1 union all
select '2014-06-01 10:39:00',2,15 union all
select '2014-06-01 11:39:00',3,10 union all
select '2014-06-02 12:39:00',4,11 union all
select '2014-06-03 13:39:00',5,13 union all
select '2014-06-04 14:39:00',6,14
--------------生成数据--------------------------
select CONVERT(VARCHAR(10),[dateteme],23)[dateteme],SUM([shuliang])+SUM([shuliang2]) AS shuliang
from [huang]
GROUP BY CONVERT(VARCHAR(10),[dateteme],23)
----------------结果----------------------------
/*
dateteme shuliang
---------- -----------
2014-06-01 32
2014-06-02 15
2014-06-03 18
2014-06-04 20
*/
------解决方案--------------------
select to_char( datetime,'yyyy-mm-dd') as dd,sum( shuliang +shuliang2)
from tabname group by to_char( datetime,'yyyy-mm-dd') order by dd
------解决方案--------------------
大版写的比较规范,
把
CONVERT(VARCHAR(10),[dateteme],23)[dateteme]
换成oracle 的函数
to_char( datetime,'yyyy-mm-dd') 就OK了~
应该到oracle 版去问
------解决方案--------------------
select to_date(dateteme,'yyyy-mm-dd') "datetime",
sum(shuliang+shuliang2) "shuliang"
from [表名]
group by to_date(dateteme,'yyyy-mm-dd')
------解决方案--------------------