回复: 15
跳转到指定楼层
上一主题 下一主题
收起左侧

Wayfair OA 两道SQL

全局:

2019(1-3月) 分析|数据科学类 硕士 全职@wayfair - 网上海投 - 在线笔试  | | Other | 应届毕业生
60分钟两道SQL,看地理没有题目的
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies


. Χ

. 1point3acres.com

本帖子中包含更多资源

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x

评分

参与人数 4大米 +18 收起 理由
努力加餐饭 + 1 给你点个赞!
cuteflydragon + 1 很有用的信息!
rongy2018 + 1 很有用的信息!
匿名用户-GC9YL + 15

查看全部评分


上一篇:Akuna OA Quant Dynamic - 2019 (Python Only)
下一篇:Wayfair Analytics Challenge
推荐
rongy2018 2019-4-21 05:37:25 | 只看该作者
全局:
vivianinus 发表于 2019-4-15 23:04
公车:
WITH on_board AS (
    SELECT p.id  AS p_id, MIN(CAST(b.time AS TIME)) AS b_time

赶汽车的那道题, 不知道这么写对不对?. check 1point3acres for more.
with best_catch as (
        select p.id as passenger_id, b.id as bus_id, row_number() over(partition by p.id order by b.time) as row_num
        from passengers p
        right  join buses b
        on p. origin=b.origin and p.destination =b.destination and p.time<=b.time
)
select bus_id, coalesce(count(passenger_id) ,0) . From 1point 3acres bbs
from best_catch
where row_num=1 or p. id is null
group by 1
回复

使用道具 举报

推荐
cuteflydragon 2020-11-20 01:51:42 | 只看该作者
全局:
vivianinus 发表于 2019-4-15 07:04
公车:
WITH on_board AS (
    SELECT p.id  AS p_id, MIN(CAST(b.time AS TIME)) AS b_time

Happy Duck:

SELECT D.pond_id, SUM(CASE WHEN ((temp_preference='+' AND temperature>temp_limit) OR
                                                                                                  (temp_preference='-' AND temperature<temp_limit) ) THEN 1 ELSE 0
                                                                                                                                                                 END) as Happy_ducks
        FROM ducks D JOIN species S-baidu 1point3acres
        ON D.specied_id=S.id
        JOIN ponds P.--
        ON P.id=D.pond_id
GROUP BY pond_id. 1point3acres
ORDER BY pond_id
回复

使用道具 举报

全局:
you are welcome
drop table buses, passengers;
create table buses (bus_id int primary key, origin varchar not null, destination varchar not null, time varchar not null, unique(origin, destination, time));                               
INSERT INTO buses (bus_id, origin, destination, time) VALUES. .и
(10, 'W', 'B', '10:55'),
(20, 'B', 'P', '06:20'),
(21, 'B', 'P', '14:00'),-baidu 1point3acres
(22, 'B', 'P', '21:40'),
(30, 'P', 'M', '13:30');
. 1point3acres
create table passengers (pass_id int primary key, origin varchar not null, destination varchar not null, time varchar not null);                               
INSERT INTO passengers (pass_id, origin, destination, time) VALUES
(1, 'P', 'M', '13:30'),. Χ
(2, 'P', 'M', '13:31'),
(10, 'W', 'P', '10:00'),. check 1point3acres for more.
(11, 'W', 'B', '22:31'),
(40, 'B', 'P', '06:15'),. check 1point3acres for more.
(41, 'B', 'P', '06:50'),. check 1point3acres for more.
(42, 'B', 'P', '07:12'),
(43, 'B', 'P', '12:03'),
(44, 'B', 'P', '20:00');
select b.id, count(p.id) from buses b join passengers p on p.origin = b.origin and p.destination = b.destination and p.time <= b.time group by b.id order by b.id. ----

-- 对每一个passager来说,最小的bus arrival time 就是他要乘的
with tmp as (
select p.pass_id, min(b.time) as boarding_time
from buses b join passengers p on p.origin = b.origin and p.destination = b.destination and p.time <= b.time
group by p.pass_id. 1point 3 acres
order by p.pass_id)

select b.bus_id as id, count(pass_id)
from buses b
left join tmp
on b.time = tmp.boarding_time
group by id.--
order by id
回复

使用道具 举报

🔗
EmmaSwan 2019-3-7 11:22:08 | 只看该作者
全局:
感谢楼主!这两道是不是都是用case做出来的啊?
回复

使用道具 举报

全局:
求分享duck的解法~~谢谢!
回复

使用道具 举报

🔗
 楼主| 少女喵 2019-3-9 07:15:53 来自APP | 只看该作者
全局:
已注销用户-4990 发表于 2019/03/09 07:03:21
求分享duck的解法~~谢谢!

好的呢 等我晚上做了发哦
回复

使用道具 举报

全局:
那个等车的题有谁能做出来呀…… 求思路 不知道怎么解决时间最近的那班车的问题
回复

使用道具 举报

🔗
vivianinus 2019-4-15 23:04:38 | 只看该作者
全局:
公车:. 1point3acres.com
WITH on_board AS (
    SELECT p.id  AS p_id, MIN(CAST(b.time AS TIME)) AS b_time
    FROM passengers p
    LEFT JOIN buses b ON b.origin = p.origin AND b.destination = p.destination
        AND CAST(b.time AS TIME) >= CAST(p.time AS TIME)
    GROUP BY p.id-baidu 1point3acres
)
SELECT b.id, COUNT(b_time)
FROM on_board ob
LEFT JOIN passengers p ON ob.p_id = p.id. From 1point 3acres bbs
LEFT JOIN buses b ON (p.origin = b.origin AND p.destination = b.destination)
    AND (ob.b_time = CAST(b.time AS TIME) OR b_time IS NULL)
GROUP BY b.id. .и
ORDER BY b.id

ducks:
SELECT p.id AS pond_id,
    SUM(CASE WHEN s.temp_preferences = '+' AND
                  p.temperature >= s.temp_limit THEN 1
             WHEN s.temp_preferences = '-' AND
                  p.temperature <= s.temp_limit THEN 1 . ----
             ELSE 0 END) AS happy_ducks
from ponds p
LEFT JOIN ducks d ON d.pond_id = p.id. From 1point 3acres bbs
LEFT JOIN species s ON s.id = d.species_id. check 1point3acres for more.
GROUP BY p.id
ORDER BY p.id

评分

参与人数 3大米 +3 收起 理由
Ivy97 + 1 给你点个赞!
Fuxiong + 1 赞一个
rongy2018 + 1 给你点个赞!

查看全部评分

回复

使用道具 举报

🔗
rongy2018 2019-4-21 00:26:48 | 只看该作者
全局:
楼主申请的是什么职位啊?
回复

使用道具 举报

全局:
楼主可以分享一下公车的解法?谢谢哈
回复

使用道具 举报

🔗
HoraceWang 2019-9-26 09:27:49 | 只看该作者
全局:
select b1.id, count(p1.id) as passengers_on_board
from buses b1 left join (
select p.id, min(b.time) as earliest_time
from buses b left join passengers p on b.origin=p.origin and b.destination=p.destination and b.time>=p.time ..
                        group by 1
) p_b
        on b1.time=p_b.earliest_time
left join passengers p1 on p1.id=p_b.id
group by 1
order by 1;
回复

使用道具 举报

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

本版积分规则

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