-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New kilkari sql queries which maybe useful for future report generation
- Loading branch information
1 parent
3495bea
commit 3366b41
Showing
9 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
select *, | ||
case when A.Subscriber_Pack_ID=1 | ||
then (72*7-datediff(A.Activation_Date,A.Lmp)) | ||
else (48*7-datediff(A.Activation_Date,A.Date_Of_Birth)) | ||
end as days_supposed_to_be_in_system , | ||
CASE WHEN A.fulldate is NULL | ||
THEN datediff('2016-06-29',A.Activation_Date) | ||
ELSE datediff('2016-06-29',A.fulldate) | ||
END as days_since_last_success | ||
from (select subs.MS_ISDN,ss.Name,v.village_name,ss.Subscriber_ID,subs.Activation_Date, | ||
sd.State_Name as state_name,dd.district_name as district_name,max(dt.FullDate) as fulldate,subs.Subscriber_Pack_ID, | ||
ss.Lmp,ss.Date_Of_Birth,scm.Subscription_Start_Date,b.healthblock_name,sf.healthsubfacility_name | ||
from subscriber_call_measure as scm | ||
left join subscriptions as subs on scm.Subscription_ID=subs.Subscription_ID and subs.Subscription_Status='ACTIVE' | ||
left join subscribers as ss on ss.Subscriber_ID=subs.Subscriber_ID | ||
left join date_dimension as dt on scm.End_Date_ID=dt.ID | ||
left join state_dimension as sd on sd.State_ID=ss.State_ID | ||
left join district_dimension as dd on dd.Id=ss.District_ID | ||
left join village_dimension as v on v.Id=ss.Village_ID | ||
left join healthblock_dimension b on b.Id=ss.HBlock_ID | ||
left join healthsubfacility_dimension sf on sf.Id=ss.HSub_Facility_ID | ||
where scm.Call_Status='SUCCESS' and scm.Call_Source='OBD' | ||
group by ss.Subscriber_ID,subs.MS_ISDN) A | ||
|
||
--days since last successful call(reporting database) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
select b.State_Name, b.district_name, b.MS_ISDN,count(*) from subscriber_call_measure scm | ||
left join subscriptions sub on sub.Subscription_ID=scm.Subscription_ID | ||
left join (select subs.MS_ISDN,subs.Activation_Date,subs.Last_Modified_Time,dt.FullDate as Last_Success, | ||
sd.State_Name as state_name,dd.district_name as district_name,max(dt.FullDate) as fulldate | ||
from subscriber_call_measure as scm | ||
left join subscriptions as subs on scm.Subscription_ID=subs.Subscription_ID and subs.Subscription_Status='ACTIVE' | ||
left join subscribers as ss on ss.Subscriber_ID=subs.Subscriber_ID | ||
left join date_dimension as dt on scm.End_Date_ID=dt.ID | ||
left join state_dimension as sd on sd.State_ID=ss.State_ID | ||
left join district_dimension as dd on dd.Id=ss.District_ID | ||
where scm.Call_Status='SUCCESS' and scm.Call_Source='OBD' | ||
group by subs.MS_ISDN) b on b.MS_ISDN=sub.MS_ISDN | ||
left join date_dimension d on scm.End_Date_ID=d.ID | ||
where scm.Call_Status<>'SUCCESS' | ||
and CASE WHEN b.fulldate=NULL | ||
THEN d.FullDate>date(b.Activation_Date) | ||
ELSE d.FullDate>b.fulldate | ||
END | ||
group by b.MS_ISDN | ||
order by b.State_Name, b.district_name | ||
|
||
--days since last successful call(reporting database) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
select a.callingNumber, | ||
case when sub.subscriptionPack_id_OID=1 | ||
then b.beneficiaryId | ||
else c.beneficiaryId | ||
end as beneficiaryId, | ||
case when sub.subscriptionPack_id_OID=1 | ||
then b.name | ||
else c.name | ||
end as name,s.name as state,d.name as district,hb.name as healthblock,hs.name as subfacility,v.name as village | ||
from nms_subscribers a | ||
join nms_subscriptions sub on a.id=sub.subscriber_id_OID | ||
left join nms_mcts_mothers b on a.mother_id_OID=b.id | ||
left join nms_mcts_children c on a.child_id_OID=c.id | ||
left join nms_states s on b.state_id_OID=s.id | ||
left join nms_districts d on b.district_id_OID=d.id | ||
left join nms_health_blocks hb on b.healthBlock_id_OID=hb.id | ||
left join nms_health_sub_facilities hs on b.healthSubFacility_id_OID=hs.id | ||
left join nms_villages v on b.village_id_OID=v.id | ||
where sub.subscriptionId in (select subscriptionId from nms_deactivation_subscription_audit_records where modificationDate like '2016-07-14%') | ||
--To be run on motech database with modification date being the date when deactivation was done. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
select a.callingNumber, | ||
case when sub.subscriptionPack_id_OID=1 | ||
then b.beneficiaryId | ||
else c.beneficiaryId | ||
end as beneficiaryId, | ||
case when sub.subscriptionPack_id_OID=1 | ||
then b.name | ||
else c.name | ||
end as name,s.name as state,d.name as district,hb.name as healthblock,hs.name as subfacility,v.name as village | ||
from nms_subscribers a | ||
join nms_subscriptions sub on a.id=sub.subscriber_id_OID | ||
left join nms_mcts_mothers b on a.mother_id_OID=b.id | ||
left join nms_mcts_children c on a.child_id_OID=c.id | ||
left join nms_states s on b.state_id_OID=s.id | ||
left join nms_districts d on b.district_id_OID=d.id | ||
left join nms_health_blocks hb on b.healthBlock_id_OID=hb.id | ||
left join nms_health_sub_facilities hs on b.healthSubFacility_id_OID=hs.id | ||
left join nms_villages v on b.village_id_OID=v.id | ||
where sub.subscriptionId in (select subscriptionId from nms_deactivation_subscription_audit_records where modificationDate like '2016-07-14%') | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
SELECT cds.callingNumber,cds.callId,cds.callDisconnectReason,cds.callStartTime,cds.callEndTime,cds.creationDate,cds.circle,cd.contentFileName,cd.subscriptionPack | ||
FROM nms_inbox_call_details cds | ||
left join nms_inbox_call_data cd on cds.id=cd.content_id_OWN | ||
where cds.creationDate between '2016-05-01' and '2016-06-01' | ||
order by cds.creationDate | ||
|
||
--inbox call details (motech database) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
select ss.Subscriber_ID,st.State_Name, d.district_name, s.MS_ISDN,count(*) as number_of_first_attempts,s.Activation_Date,s.Subscriber_Pack_ID | ||
from subscriber_call_measure scm | ||
left join subscriptions s on s.Subscription_ID=scm.Subscription_ID and s.Subscription_Status='ACTIVE'--taken only active subscribers | ||
left join subscribers as ss on ss.Subscriber_ID=s.Subscriber_ID | ||
left join state_dimension as st on st.State_ID=ss.State_ID | ||
left join date_dimension as dd on dd.ID=scm.End_Date_ID | ||
left join district_dimension as d on d.Id=ss.District_ID | ||
where scm.Call_Source='OBD' and scm.Attempt_Number=1 | ||
--took all 1st attempts calls for call source obd with subscriber id and subscriber_pack_id. Date is not necessary here | ||
group by ss.Subscriber_ID,s.MS_ISDN | ||
order by st.State_Name, d.district_name | ||
|
||
--The above table gives total number of first attempts made to the subscriber (reporting database) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
select sub.Subscriber_ID, sub.MS_ISDN,count(*) as number_of_calls_unsuccessful, | ||
sum(case when scm.Call_Status='NA' then 1 else 0 end) as 'NOT_Answered', | ||
sum(case when scm.Call_Status='ND' then 1 else 0 end) as 'NOT_Delivered', | ||
sum(case when scm.Call_Status='SO' then 1 else 0 end) as 'Switched_Off' --Count of all missed calls with each with count of each in the next three rows | ||
from subscriber_call_measure scm | ||
left join subscriptions sub on sub.Subscription_ID=scm.Subscription_ID | ||
where scm.Call_Status<>'SUCCESS' and scm.Call_Source='OBD' | ||
group by sub.MS_ISDN | ||
-- status-wise call unsuccessful count for outbound calls (reporting database) |
8 changes: 8 additions & 0 deletions
8
kilkari/kilkari_unanswering_msisdns_for_more_than_12_weeks.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
select distinct MS_ISDN from subscriptions | ||
where Subscription_ID not in | ||
(select distinct a.Subscription_ID | ||
from subscriber_call_measure a | ||
left join subscriptions b on a.Subscription_ID=b.Subscription_ID | ||
where b.Subscription_Status='ACTIVE' and a.Call_Status='SUCCESS') | ||
and Subscription_Status='ACTIVE' and Activation_Date<'2016-04-21'; | ||
--from motech database. The date is to be changed according to the date when you you run the query. It should be 12 weeks from the present date |
19 changes: 19 additions & 0 deletions
19
ma/Flw_per_circle_who_have_listened_to_more_than_50%_course.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
select cdm.circle_name, | ||
count(distinct cdm.calling_msisdn) | ||
from ma_call_detail_measure as cdm | ||
join ma_course_status as ma on cdm.flw_id=ma.flw_id | ||
join front_line_worker as flw on cdm.flw_id=flw.id | ||
join ma_call_content_measure as m on cdm.id=m.call_detail_id | ||
join ma_dimension as md on m.content_id=md.id | ||
where flw.flw_status='ACTIVE' and (cdm.circle_name='BI' or cdm.circle_name='MP' or cdm.circle_name='UW' or cdm.circle_name='RA') | ||
and md.content_name in ( | ||
select X.content_name from | ||
(select content_name from (select cast(trim(replace(replace(replace(content_name, 'Chapter',''),'_Lesson',''),'0','')) as unsigned) as L, content_name from ma_dimension where content_name like '%Lesson%') V | ||
where V.L > 51 | ||
union | ||
select content_name from | ||
(select cast(trim(replace(replace(replace(content_name, 'Chapter',''),'_Question',''),'0','')) as unsigned) as Q,content_name from ma_dimension where content_name like '%Question%') U | ||
where U.Q > 50) X | ||
) | ||
group by cdm.circle_name | ||
--Flws per circle who have listened to more than 50% of the course (reporting database) |