统计查询-sql

select
--总注册人数
(select COUNT(*) from [YYD_Users_RegInfo]) as TotalCount,
--pc端注册人数
(select COUNT(*) from [YYD_Users_RegInfo] where regPlatform ='pc') as PCTotalCount,
--手机端注册人数
(select COUNT(*) from [YYD_Users_RegInfo] where regPlatform ='mobile') as MobileTotalCount,
--新增总注册人数
(select COUNT(*) from [YYD_Users_RegInfo]
where Convert(varchar(10),RegTime,120) >=Convert(varchar(10),'2016-07-01',120)
and Convert(varchar(10),RegTime,120) <=Convert(varchar(10),'2016-07-06',120) ) as AddTotalCount,
--新增pc端注册人数:
(select COUNT(*) from [YYD_Users_RegInfo] where regPlatform ='pc'
and Convert(varchar(10),RegTime,120) >=Convert(varchar(10),'2016-07-01',120)
and Convert(varchar(10),RegTime,120) <=Convert(varchar(10),'2016-07-06',120)) as AddPCTotalCount,
--新增手机端注册人数
(select COUNT(*) from [YYD_Users_RegInfo] where regPlatform ='mobile'
and Convert(varchar(10),RegTime,120) >=Convert(varchar(10),'2016-07-01',120)
and Convert(varchar(10),RegTime,120) <=Convert(varchar(10),'2016-07-06',120)) as AddMobileTotalCount,

--激活总人数
(select count(distinct USER_ID) from [YYD_Account_Verification] where status =1) as TotalVerification,
--实名认证人数
(select count(distinct USER_ID) from [YYD_Account_Verification] where vtype='ver_realname' and status=1) as TotalRealnameVerification,
--新增激活总人数
(select count(distinct USER_ID) from [YYD_Account_Verification] where status =1
and Convert(varchar(10),createtime,120) >=Convert(varchar(10),'2016-07-01',120)
and Convert(varchar(10),createtime,120) <=Convert(varchar(10),'2016-07-06',120)) as AddTotalVerification,
--新增实名认证人数
(select count(distinct USER_ID) from [YYD_Account_Verification] where vtype='ver_realname' and status=1
and Convert(varchar(10),createtime,120) >=Convert(varchar(10),'2016-07-01',120)
and Convert(varchar(10),createtime,120) <=Convert(varchar(10),'2016-07-06',120)) as AddTotalRealnameVerification,
--累计开户数
(select count(distinct USER_ID) from [YYD_Account_BankAccount] where status =1) as OpenAnAccount


--充值统计
select top 1 (select count(*) from (select distinct user_id from YYD_Account_MoneyRecord where (moneytype='充值' or moneytype='线下充值') and state=1) a) People,
(select count(*) from (select distinct user_id from YYD_Account_MoneyRecord where (moneytype='充值' or moneytype='线下充值') and state=1 and createtime >=convert(varchar(100),'2016-06-29 00:00:00',20) and createtime <=convert(varchar(100),'2016-07-06 23:59:59',20) ) a) NewPeople,
(select count(*) from YYD_Account_MoneyRecord where (moneytype='充值' or moneytype='线下充值') and state=1) Number,
(select count(*) from YYD_Account_MoneyRecord where (moneytype='充值' or moneytype='线下充值') and state=1 and createtime >=convert(varchar(100),'2016-06-29 00:00:00',20) and createtime <=convert(varchar(100),'2016-07-06 23:59:59',20) ) NewNumber,
(select sum(amount) from YYD_Account_MoneyRecord where (moneytype='充值' or moneytype='线下充值') and state=1) Amount,
(select sum(amount) from YYD_Account_MoneyRecord where (moneytype='充值' or moneytype='线下充值') and state=1 and createtime >=convert(varchar(100),'2016-06-29 00:00:00',20) and createtime <=convert(varchar(100),'2016-07-06 23:59:59',20) ) NewAmount,
(select COUNT(*) from YYD_Account_MoneyRecord m inner join YYD_Account_RechargeRecord r on r.ID=m.refid where (moneytype='充值' or moneytype='线下充值') and m.state=1 and (r.recharge_type='0' or recharge_type='chinapay_b2c' or recharge_type='offline')) pcCount,
(select COUNT(*) from YYD_Account_MoneyRecord m inner join YYD_Account_RechargeRecord r on r.ID=m.refid where (moneytype='充值' or moneytype='线下充值') and m.state=1 and r.recharge_type='chinapaywap') MobileCount,
(select SUM(m.amount) from YYD_Account_MoneyRecord m inner join YYD_Account_RechargeRecord r on r.ID=m.refid where (moneytype='充值' or moneytype='线下充值') and m.state=1 and r.recharge_type='chinapaywap') MobileAmount,
(select SUM(m.amount) from YYD_Account_MoneyRecord m inner join YYD_Account_RechargeRecord r on r.ID=m.refid where (moneytype='充值' or moneytype='线下充值') and m.state=1 and (r.recharge_type='0' or recharge_type='chinapay_b2c' or recharge_type='offline')) PcAmount,
(select COUNT(*) from YYD_Account_MoneyRecord m inner join YYD_Account_RechargeRecord r on r.ID=m.refid where (moneytype='充值' or moneytype='线下充值') and m.state=1 and (r.recharge_type='0' or recharge_type='chinapay_b2c' or recharge_type='offline') and m.createtime >=convert(varchar(100),'2016-06-29 00:00:00',20) and m.createtime <=convert(varchar(100),'2016-07-06 23:59:59',20) ) NewPcCount,
(select COUNT(*) from YYD_Account_MoneyRecord m inner join YYD_Account_RechargeRecord r on r.ID=m.refid where (moneytype='充值' or moneytype='线下充值') and m.state=1 and r.recharge_type='chinapaywap' and m.createtime >=convert(varchar(100),'2016-06-29 00:00:00',20) and m.createtime <=convert(varchar(100),'2016-07-06 23:59:59',20) ) NewMobileCount,
(select SUM(m.amount) from YYD_Account_MoneyRecord m inner join YYD_Account_RechargeRecord r on r.ID=m.refid where (moneytype='充值' or moneytype='线下充值') and m.state=1 and r.recharge_type='chinapaywap' and m.createtime >=convert(varchar(100),'2016-06-29 00:00:00',20) and m.createtime <=convert(varchar(100),'2016-07-06 23:59:59',20) ) NewMobileAmount,
(select SUM(m.amount) from YYD_Account_MoneyRecord m inner join YYD_Account_RechargeRecord r on r.ID=m.refid where (moneytype='充值' or moneytype='线下充值') and m.state=1 and (r.recharge_type='0' or recharge_type='chinapay_b2c' or recharge_type='offline') and m.createtime >=convert(varchar(100),'2016-06-29 00:00:00',20) and m.createtime <=convert(varchar(100),'2016-07-06 23:59:59',20) ) NewPcAmount
from YYD_Account_MoneyRecord


--投资统计
select top 1
(select COUNT(*) from YYD_Borrow_BidRecord) BidCount,
(select COUNT(*) from (select distinct bid_user_id from YYD_Borrow_BidRecord ) data)BidUsersCount,
(select sum(amount) from YYD_Borrow_BidRecord) BidAmount,
(select SUM(repay_amount) from YYD_Borrow_RepayRecord where status=0 and repaytype='本金') DHRepayAmount,
(select COUNT(*) from YYD_Borrow_BidRecord where 1=1 {0}) NewBidCount,
(select COUNT(*) from (select distinct bid_user_id from YYD_Borrow_BidRecord where 1=1 {0}) data) NewBidUsersCount,
(select sum(amount) from YYD_Borrow_BidRecord where 1=1 {0}) NewBidAmount,
(select SUM(repay_amount) from YYD_Borrow_RepayRecord where status=1 and repaytype='本金') YHRepayAmount
from YYD_Borrow_BidRecord

原文地址:https://www.cnblogs.com/zxtceq/p/5703732.html