123
返回列表 发新帖
楼主: 七瓣酱
跳转到指定楼层
上一主题 下一主题
收起左侧

FB DS电面面经

🔗
waf616yeah 2018-8-31 09:05:25 | 只看该作者
全局:
Select big.advertiser_id, count(big.user_id) as num from
(Select advertiser.advertiser_id, advertiser.ad_id, user.user_id, user.price from advertiser left join user on (user.ad_id = advertiser.ad_id)) big
where big.price > 0 or big.price is null [some ads have no customers]
Group by big.advertiser_id
having num > 0

ROI: by advertiser. 1point 3acres
Select revenue.adertiser_id, (revenue.revenue-cost.cost)/cost.cost as ROI from
(
Select sub1.advertiser_id, sum(ifnull(user.price, 0)) as revenue from
        (Select a1.advertiser_id, a1.ad_id, u1.user_id, u1.price
        from advertiser a1
        left join user u1 on (user.ad_id = advertiser.ad_id)) sub1 . check 1point3acres for more.
) revenue
Inner join . 1point3acres.com
(
Select a2.advertiser_id, sum(a2.spend) as cost from advertiser a2 group by a2.advertiser_id
) cost
On cost.advertiser_id = revenue.advertiser_id
回复

使用道具 举报

🔗
love小P 2018-9-21 05:59:39 | 只看该作者
全局:
我觉得这题可以两个subquery也可以直接写。。。
我的习惯都是写subquery思路清晰一些,但是subquery并不efficient
请问大家,这些大公司的DS面试要是写的不efficient会减分吗??
回复

使用道具 举报

🔗
gatescao 2018-12-18 08:33:13 | 只看该作者
全局:
(1) Ads whose ad_id don't appear in the user table is not converted. We can use INNER JOIN here.
  1. SELECT (COUNT DISTINCT advertiser_id) AS num_advertiser
  2. FROM. 1point 3acres
  3. advertiser
  4. INNER JOIN user
  5. ON advertiser.ad_id = user.ad_id
复制代码


(2) Two cases here:
No.1: ROI on every ad_id
  1. SELECT advertiser_id, ad_id, SUM(IFNULL(price,0)) / spend. 1point 3acres
  2. FROM advertiser
  3. LEFT JOIN user
  4. ON advertiser.ad_id = user.ad_id. 1point 3 acres
  5. GROUP BY advertiser_id, ad_id
复制代码


No.2: ROI for every advertiser_id
  1. SELECT advertiser_id, SUM(IFNULL(rev,0)) / SUM(spend) AS ROI
  2. FROM
  3. advertiser
  4. LEFT JOIN
  5. (SELECT ad_id, SUM(price) AS rev
  6. FROM user
  7. GROUP BY ad_id) tbl1
  8. ON advertiser.ad_id = tbl1.ad_id
  9. GROUP BY advertiser_id
复制代码
.1point3acres
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表