You are on page 1of 5

--1) How many number of territories are assigned to the salesforce SALESFORCE_SP

select count(TERRITORY_ID) as Number_of_Ter, TERRITORY_ID from calls_assignment


where SALESFORCE_ID= 'SALESFORCE_SP'
group by TERRITORY_ID

--2) How many number of doctors are assigned per territory in salesforce
SALESFORCE_STR

select count(DOC_ID) as Number_of_Doc, TERRITORY_ID from calls_assignment


where SALESFORCE_ID= 'SALESFORCE_STR'
group by TERRITORY_ID

--3) Calculate the annual PDEs(000s) for PRODUCT_S AND PRODUCT_M

Select count(P1) * CALLS as SP1 into t1 from calls_assignment


where P1= 'PRODUCT_S'
Group by calls

Select count(P2) * .5 * calls as SP2 into t2 from calls_assignment


where P2= 'PRODUCT_S'
group by calls
select SUM (SP2) from t2
select SUM (SP1) from t1
drop table t2
select (20097 + 115491)*2

--4) Out of total calls made for Product E, what is the percentage of calls made at
position P1.

select sum(calls) from calls_assignment where P1= 'PRODUCT_E'


select sum(calls) from calls_assignment where P1= 'PRODUCT_E' OR P2 = 'PRODUCT_E'
SELECT cast(18111/104787 as decimal(18,3))

-- 5) Out of total doctors called for product_W in all sales forces, what is the
percentage of doctors being called on for PRODUCT_W by reps in salesforce
SALESFORCE_SP

select COUNT(DOC_ID) from calls_assignment where P1 = 'PRODUCT_W' or P2 = 'PRODUCT_W'


select COUNT(DOC_ID) from calls_assignment where (P1 = 'PRODUCT_W' or P2 = 'PRODUCT_W')
AND SALESFORCE_ID= 'SALESFORCE_SP'

-- 6) What percentage of physicians in Quintile Q3 are being called on for PRODUCT_W

select count(t2.DOC_ID) from


product_quintile as t2

where t2.PRODUCT_W_QUINTILE = 3

select count(t1.DOC_ID) from


calls_assignment as t1 inner join product_quintile as t2
on t1.DOC_ID=t2.DOC_ID
where t2.PRODUCT_W_QUINTILE = 3
and ( t1.P1 = 'PRODUCT_W' or t1.P2 = 'PRODUCT_W')
-- 7) Frequency for quintile Q5 for PRODUCT_W is?
Select count(P1) * CALLS as SP1 from calls_assignment
where P1= 'PRODUCT_W'
Group by calls

Select count(P2) * .5 * calls as SP2 from calls_assignment


where P2= 'PRODUCT_W'
group by calls
select SUM (SP2) from t4
select SUM (SP1) from t3

select (80241)

select count(DOC_ID) from product_quintile


where PRODUCT_W_QUINTILE = 5

-- 8) Number of P2 calls (000s) given by sales force team SALESFORCE_STR for


PRODUCT_S ?
select sum (CALLS)
from calls_assignment
where P2 = 'PRODUCT_S' and SALESFORCE_ID= 'SALESFORCE_STR'

--9) What are the total PDEs(000s) for specialty group 1PAIN_MEDICINE for PRODUCT_M

Select (count(P1) * CALLS) as SP1, calls into t100 from calls_assignment as t20 INNER
JOIN spec_specgroup_mapping as t23
ON T20.DOC_ID = T23.DOC_ID
where t20.P1= 'PRODUCT_M' and t23.SPEC_GROUP = '1PAIN_MEDICINE'
Group by calls

Select (count(P2) * .5 * calls) as SP2 into t101 from calls_assignment as t20 INNER JOIN
spec_specgroup_mapping as t23
ON T20.DOC_ID = T23.DOC_ID
where t20.P2= 'PRODUCT_M' and t23.SPEC_GROUP = '1PAIN_MEDICINE'
group by calls
select SUM (SP2) from T101
select SUM (SP1) from T100

DROP TABLE T101


DROP TABLE T100

select 51058.5+102117

--10) What are the total PDEs (000) and calls (000) for PRODUCT_W in quintile Q5?

Select count((P1)*CALLS) as SP1 from


calls_assignment as t20 INNER JOIN PRODUCT_QUINTILE as t22
ON T20.DOC_ID = T22.DOC_ID
where t20.P1='PRODUCT_W' and PRODUCT_W_QUINTILE=5
Group by calls

Select (count(P2) * .5 * calls) as SP2 INTO T101 from calls_assignment as t20 INNER JOIN
PRODUCT_QUINTILE as t23
ON T20.DOC_ID = T23.DOC_ID
where t20.P2= 'PRODUCT_W' and PRODUCT_W_QUINTILE = 5
group by calls
select SUM (SP2) from T101
select SUM (SP1) from T100

DROP TABLE T101

--11) Number of doctors common for PRODUCT_M and PRODUCT_W


select count (doc_id) from calls_assignment where p1= 'PRODUCT_M' and p2='PRODUCT_W'

--12) Number of doctors being called upon for PRODUCT_E


select count(doc_id) from calls_assignment where p1= 'PRODUCT_E' OR p2 = 'PRODUCT_E'

-- 13) Calculate the PDE ratio of all the products in order PRODUCT_M, PRODUCT_W,
PRODUCT_S, PRODUCT_E for territory AXBCAECS1
select (count(P1) * calls) as sp1 into t200 from calls_assignment
where p1= 'PRODUCT_M' and territory_id = 'AXBCAECS1'
group by calls

(select sum(sp1) from t200 )

sELECT (COUNT(P2) * CALLS * .5) as sp2 into t206 from calls_aSsignment


where p2= 'PRODUCT_W' and territory_id = 'AXBCAECS1'
group by calls

select sum(sp1) from t200


select sum(sp2) from t206

SELECT
(SELECT(select (select sum(sp1) from t200 )
+ (select sum(sp2) from t201)) )
/

(SELECT((select sum(sp1) from t200 )


+ (select sum(sp2) from t201) + (select sum(sp2) from t206) +

(select sum(sp1) from t204 )


+ (select sum(sp2) from t205) +
(select sum(sp1) from t202 )
+ (select sum(sp2) from t203)))

drop table t200,t201,t202,t203,t204,t205,t206

-- 16) Calculate the unique and common doctors called for product W and product S.
Represent this scenario through a venn diagram.

select count(DISTINCT doc_id) from Calls_ASSIGNMENT where p1='PRODUCT_S' and


P2='PRODUCT_W'
select count(DISTINCT doc_id) from Calls_ASSIGNMENT where p1='PRODUCT_S' or
P2='PRODUCT_S'
select count(DISTINCT doc_id) from Calls_ASSIGNMENT where P2='PRODUCT_W'

-- 18) Which area has got the maximum doctors who are being called on for product W in
quintile 5?

select count(t1.doc_id) as NODs, TERRITORY_ID from calls_assignment as t1 inner join


product_quintile as t2
on t1.doc_id = t2.doc_id
where t1.p2 = 'PRODUCT_W' AND t2.PRODUCT_W_QUINTILE = 5
group by TERRITORY_ID
select * from t300
select territory_id from t300 where NODs in (select max(NODs) from t300)

-- 14) Alter table call assignment to add another column called Spec_group
-- 15) Update spec-group column with appropriate speciality group types using spec to
spec group mapping table.

alter table calls_assignment


add Spec_group Varchar(50)
update calls_assignment
set Spec_group = t2.spec_group

from calls_assignment as t1 inner join spec_specgroup_mapping as t2


on t1.doc_id = t2.doc_id

select * from Calls_ASSIGNMENT

-- 19) Alter table call assignment to add column PDEs_product_M. Update PDE_product_M
with the PDEs values for product M.

selecT CALLS as SP1, DOC_ID into t400 from calls_assignment

where Calls_ASSIGNMENT.P1= 'PRODUCT_M'

Select (.5 * calls) as SP2, DOC_ID into t401 from calls_assignment

where Calls_ASSIGNMENT.P2= 'PRODUCT_M'

alter table calls_assignment


add PDEs_PRODUCT_M numeric
update Calls_ASSIGNMENT
set PDEs_PRODUCT_M = t400.SP1
from Calls_ASSIGNMENT as t1 inner join t400
on t1.DOC_ID = t400.DOC_ID
where t1.p1= 'PRODUCT_M'

select * from Calls_ASSIGNMENT

update Calls_ASSIGNMENT
set PDEs_PRODUCT_M = t401.SP2
from Calls_ASSIGNMENT as t1 inner join t401
on t1.DOC_ID = t401.DOC_ID
where t1.p2= 'PRODUCT_M'

select * from Calls_ASSIGNMENT

-- 17) Generate a summary of unique doctors by areas and specialty group which are being
called upon for product S.

select AREA_ID , count(DISTINCT t1.DOC_ID) as Total_number_of_doctors , t2.spec_group


from calls_assignment as t1 inner join spec_specgroup_mapping as t2
on t1.doc_id = t2.doc_id
where P1 = 'PRODUCT_S' or P2= 'PRODUCT_S'

GROUP BY AREA_ID, t2.SPEC_GROUP

-- 20) Generate a summary of total calls by different selling teams and products.
Illustration shown below

select Calls_ASSIGNMENT.SALESFORCE_ID, Calls_ASSIGNMENT.P1 as Product , sum(CALLS) as


[Total number of calls]
into tp1 from Calls_ASSIGNMENT
group by SALESFORCE_ID, Calls_ASSIGNMENT.P1
select Calls_ASSIGNMENT.SALESFORCE_ID, Calls_ASSIGNMENT.P2 as Product , sum(CALLS) as
[Total number of calls]
into tp2 from Calls_ASSIGNMENT
group by SALESFORCE_ID, Calls_ASSIGNMENT.P2

create table Products2 ( SALESFORCE_ID varchar(50) , Product varchar(50) , [Total number


of calls] numeric)
insert into Products2
select * from tp1
insert into Products2
select * from tp2

select * from Products2

Select * from Calls_ASSIGNMENT

select Calls_ASSIGNMENT.SALESFORCE_ID, Calls_ASSIGNMENT.P1 as Product , sum(CALLS) as


[Total number of calls]
into tp1 from Calls_ASSIGNMENT

You might also like