日期:2014-05-18  浏览次数:20816 次

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)