Forum

Posted by Li, April 2, 2022, 8:48 p.m.

The solution for problem #100

SELECT advertiser_id, SUM(CASE WHEN AI.ad_id IS NULL THEN 0 ELSE spend END)*1.0/sum(distinct cost) as roi 
FROM advertiser A
LEFT JOIN ad_info AI
ON A.ad_id = AI.ad_id 
GROUP BY advertiser_id

 

Here is my solution.  The query results are almost same with the official results except one row ( 2.5578947368421048  --- 2.557894736842105)  .  But, it was judged wrong answer.  What is the error?  Thanks. 

 

Answers

What is the logic of summing up distinct costs as in sum(distinct cost)? Think that part needs to be changed.

SQLPad user avatar

Leon (949)

April 3, 2022, 8:47 p.m.