日期:2014-05-16 浏览次数:20623 次
ALTER PROCEDURE proc_getStatisticalInformation
@account VARCHAR(50) = '',
@gameNo INT = -1,--游戏编号,3位整数
@platNo INT = -1,--平台编号,3位整数
@svrNo INT = -1,
@startTime DATETIME='1900-01-01',
@endTime DATETIME='1900-01-01'
--,@isFirst BIT=-1 --是否首次充值,1是,0否
AS
DECLARE @allTable VARCHAR(4000)
SET @allTable = '
select tab.userName,tab.svrId,SUBSTRING(CAST(gameId AS VARCHAR(6)),1,3) AS gameName,SUBSTRING(CAST(gameId AS VARCHAR(6)),4,3) AS platName,tab.amount,tab.payTime from (
SELECT userName,gameId,svrId,realamount/100 AS amount,complatetime AS payTime FROM dbo.skPayorder
UNION ALL
SELECT userName,gameId,svrId,[money],paytime FROM danglePayorder
/*
...省去N多表
*/
) as tab
'
DECLARE @sql VARCHAR(5000)
SET @sql='declare @t table(id int identity(1,1), username varchar(50),svrid INT,gameName INT,platName INT,amount DECIMAL(18,2),paytime DATETIME)
INSERT INTO @t ( username, svrid, gameName, platName, amount, paytime )
SELECT tab.userName,tab.svrId,tab.gameName,tab.platName,tab.amount,tab.payTime FROM
(
'+@allTable+'
) AS tab
WHERE 1=1 '
IF(LTRIM(RTRIM(@account)) != '')
BEGIN
SET @sql += ' AND tab.username LIKE ''%'+@account+'%'''
END
IF(@gameNo != -1)
BEGIN
SET @sql+= ' AND SUBSTRING(CAST(gameId AS VARCHAR(6)),1,3) = '+RTRIM(@gameNo)+' '
END
IF(@platNo != -1)
BEGIN
SET @sql += ' AND SUBSTRING(CAST(gameId AS VARCHAR(6)),4,3) = '+RTRIM(@platNo)+' '
END
IF(@svrNo != -1)
BEGIN
SET @sql += ' AND tab.svrId='+RTRIM(@svrNo)+' '
END
IF(@startTime > '1900-01-01')
BEGIN
SET @sql += ' AND tab.payTime >= '''+RTRIM(@startTime)+''' '
END
IF(@endTime > '1900-01-01')
BEGIN
SET @sql += ' AND tab.payTime <= '''+RTRIM(@endTime)+''' '
END
SET @sql += ' SELECT id,username,svrid,gameName,platName,amount,paytime FROM @t '
--用户充值总金额,用户充值总次数,充值用户名,游戏名称————(按照用户名和用户名分组排序)
--SET @sql += ' SELECT sum(amount) as pricecount,count(username) paycount,username,gamename FROM @t group by username,gamename '
--充值总金额,充值总人数(根据不同的游戏来统计总人数,然后累加)
SET @sql += ' SELECT sum(_tab.pricecount) totalAmountRecharge,count(_tab.username) totalNumberRecharge from ( SELECT sum(amount) as pricecount,count(username) paycount,username,gamename FROM @t group by username,gamename ) AS _tab '
-------------SET @sql += '&nbs