以下列有两个表:
table1: asin_details(asin,contact_id) primary key: contact_id
table2: contact_details(contact_date,contact_id,hmd_response(y or n)) primary key: contact_id
我要使用名为no的公式从上述数据中找到特定的百分比。是/否y的* 100被称为"FRR"
所以,实际的问题是找到客户在01-jan-2013 and 31-dec-2013
我实际上正在努力处理您需要从上面提供的日期计算"FRR"
的部分。请帮忙。
谢谢,
答案 0 :(得分:0)
SELECT (( select count(hmd_response) from contact_details where hmd_response= 'n')/( select count(hmd_response) from contact_details where hmd_response= 'y') )*100 as FRR
from asin_details A
join contact_details C
on c.contact_id = A.contact_id
where contact_date between '01-jan-2013' and '31-dec-2013'
OR
SELECT ( ( select count(hmd_response) from contact_details where hmd_response= 'n'
AND between '01-jan-2013' and '31-dec-2013')/
( select count(hmd_response) from contact_details where hmd_response= 'y'
AND between '01-jan-2013' and '31-dec-2013') )*100 as FRR
试试看,告诉我。
我基本上计算y和n的计数,然后我计算FRR。
答案 1 :(得分:0)
应该是这样的:
SELECT
a.asin,
((count(case c.hmd_response when 'n' then 1 end) /
count(case c.hmd_response when 'y' then 1 end)) * 100) as FRR,
a.contact_id
from asin_details a
join contact_details c
on a.contact_id = c.contact_id
where c.contact_date between '01-jan-2013' and '31-dec-2013'