Power Call record statistics query SQL

Source: Internet
Author: User
Tags joins

DECLARE @startTime datetime
Set @startTime = ' 2016-07-12 '

SELECT * FROM (
--seat number/Phone number/total length of call
Select Zuoxi as Zuoxi1,count (1) as Phonecount,sum (DATEDIFF (ss,jtdate,enddate)) PHONECOUNTSC from Hur_telcallrecord where Vdef2=1 and
--convert (varchar), jtdate,120) = ' 2016-07-12 '
DATEDIFF (day,jtdate, ' 2016-07-12 ') <15
GROUP BY Zuoxi
) X1 Left JOIN (
----Number of registered users
SELECT Tr.zuoxi as Zuoxi2,count (1) as Regusercount from [dbo]. Yyd_users_userinfo u INNER join yyd_users_reginfo R on u.user_id=r.id right JOIN [Hur_telcallrecord] tr on U.phone=tr.phon E
WHERE CONVERT (VARCHAR (), regtime,120) = ' 2016-07-12 ' and
DATEDIFF (day,tr.jtdate, ' 2016-07-12 ') <15
GROUP by Zuoxi
) x2 on x1.zuoxi1 = X2.zuoxi2 left JOIN (

--Recharge Total amount
SELECT Tr.zuoxi as Zuoxi3,sum (amount) as Rechargeamount from Yyd_account_moneyrecord m INNER joins Yyd_users_userinfo u on M.user_id=u.id Right JOIN
[Hur_telcallrecord] TR on U.phone=tr.phone
WHERE (moneytype= ' recharge ' or moneytype= ') and state=1 and CONVERT (VARCHAR (Ten), paytime,120) = ' 2016-07-12 ' and
DATEDIFF (day,tr.jtdate, ' 2016-07-12 ') <15
GROUP by Zuoxi
) X3 on X1.zuoxi1=x3.zuoxi3 left JOIN (
--Total investment amount
SELECT Tr.zuoxi as Zuoxi4,sum (amount) as Bidamount from Yyd_borrow_bidrecord m INNER joins Yyd_users_userinfo u on M.bid_us Er_id=u.id right JOIN [Hur_telcallrecord] tr on U.phone=tr.phone
WHERE M.status=1 and CONVERT (VARCHAR (), createtime,120) = ' 2016-07-12 '
and borrow_id in (select borrow_id from Yyd_borrow_borrowinfo_ext as ext where ext.borrow_product<>50) and
DATEDIFF (day,tr.jtdate, ' 2016-07-12 ') <15
GROUP by Zuoxi
) x4 on X1.zuoxi1=x4.zuoxi4

Power Call record statistics query SQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.