SQL查询--在查找特定百分比时需要帮助吗
有两个表,其中包含以下列:SQL查询--在查找特定百分比时需要帮助吗,sql,Sql,有两个表,其中包含以下列: 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 我必须使用一个称为n的数量/y的数量*100的公式从上述数据中找出具体的百分比,该公式被称为“FRR” 因此,实际的问题是找到客户在2013年1月1日至201
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
我必须使用一个称为n的数量/y的数量*100的公式从上述数据中找出具体的百分比,该公式被称为“FRR”
因此,实际的问题是找到客户在2013年1月1日至2013年12月31日期间与我们联系的所有asin的“FRR”
实际上,我正在努力解决您需要从上面提供的日期开始计算“FRR”的部分。请帮忙
谢谢
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'
或
试试这个,让我知道
我基本上是在计算y和n的计数,然后计算FRR 应该是这样的:
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'
成功了!谢谢没想到会这么简单。我想我需要更多的练习。再次感谢!
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'