欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

按日期统计收益,一天的收益数据合并为一条。一天一条数据

程序员文章站 2022-05-27 13:34:06
存储过程!~ ......
--统计今日金额合并为一条。一天一条数据
create proc sp_tablename
@uid int,
@bid int
as
begin
        select   sum([money]) as [money], convert(varchar(100), createtime, 23) as createtime
from      dbo.tablename
where   (uid = @uid) and (mid = @bid)
group by convert(varchar(100), createtime, 23)
end


--分页:
create proc sp_tablenamebypage
@uid int,
@bid int,
@pageindex int=1, -- 第几页
@pagesize int=10  -- 每页包含的记录数
@pagecount int output,    --总页数
@datacount int output    --总的记录条数
as
begin
      select top (select @pagesize) *     -- 这里注意一下,不能直接把变量放在这里,要用select
    from (select row_number() over(order by  convert(varchar(100), createtime, 23)) as rownumber, sum([money]) as [money],
     convert(varchar(100), createtime, 23) as createtime
    from  dbo.tablename where (uid = @uid) and (bonusid = @bid) 
    group by convert(varchar(100), createtime, 23)) temp_row 
    where  rownumber>(@pageindex-1)* @pagesize;

    set @datacount = (select count(*) from dbo.tablename)
    set @pagecount = (ceiling(@datacount*1.0/@pagesize))
 end

存储过程!~