按日期統計收益,一天的收益數據合併爲一條。一天一條數據

--統計今日金額合併爲一條。一天一條數據
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

存儲過程!~ui

相關文章
相關標籤/搜索