存儲過程!~ ...
--統計今日金額合併為一條。一天一條數據 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
存儲過程!~