2014-04-01 40 views
0

有兩個表的下方列需要幫助。的n/no。 Y's * 100將其稱作"FRR"SQL查詢中找到特定百分比

因此,實際的問題是要找到「FRR」所有的ASIN的與客戶01-jan-2013 and 31-dec-2013

之間聯繫我們,我實際上是與部分掙扎,你需要從上面提供的日期計算"FRR"。請幫忙。

感謝,

回答

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。

+0

它的工作!謝謝!不知道它可能如此簡單。猜猜我需要更多的練習。再次感謝! – user3174463

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'