当前位置: 代码迷 >> Sql Server >> SUM 函数无法使用,该怎么解决
  详细解决方案

SUM 函数无法使用,该怎么解决

热度:221   发布时间:2016-04-27 14:00:38.0
SUM 函数无法使用
String sql="select id,ball,timedata,sum(ball) as total from buy where timedata between '"+date1+"' and '"+date2+"' group by timedata,id,ball";
1.我想按timedata的顺序把同一天内的ball(金额)加一块。
但是改语句运行以后是antimedata排列但是金额没有累计
求解


------解决方案--------------------
C# code
String sql="select id,timedata,sum(ball) as total from buy where timedata between '"+date1+"' and '"+date2+"' group by timedata,id";//ball参与聚合,不用出现在group by中
------解决方案--------------------
探讨

C# code

String sql="select id,timedata,sum(ball) as total from buy where timedata between '"+date1+"' and '"+date2+"' group by timedata,id";
//ball参与聚合,不用出现在group by中

------解决方案--------------------
select convert(varchar(10),timedata,120) date,sum(ball) as total
from tb
where timedata between ... and ...
group by convert(varchar(10),timedata,120)
  相关解决方案