查看: 4481| 回复: 29
跳转到指定楼层
上一主题 下一主题
收起左侧

新人发帖,分享DS、BIE、DE、SDE、TPM、PM面试经验

全局:

注册一亩三分地论坛,查看更多干货!

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

x
本帖最后由 李浩泉 于 2020-6-15 20:33 编辑

新人不能回帖,只能在聊聊记录一下自己的思路。

感谢@anna51100 - 亚麻BIE电面

Q1. Find the number of the products available by market place.


Q2. Find the top 3 and bottom 3 product sold in Dec 2019.
Hint1:可否用join替代windows function提高效率?

Q3. Find the products in the marketplace 1 with at least 100 repeat customers in the last 1 month
Repeat customers is a customer who buys same products on 2 consecutive days

Q4. We have customers, their total purchases (dollar value) in last year (2019)
As a BIE, what visualization would you do to report to stakeholders about this.







评分

参与人数 7大米 +10 收起 理由
ychen134 + 1 很有用的信息!
zjpjhf + 2 给你点个赞!
zshi74 + 1 赞一个!
霸王 + 3 给你点个赞!
lzhllnm211 + 1 赞一个

查看全部评分


上一篇:业余爱好和我旁门左道的英语学习法相结合,及其他
下一篇:今天喜欢的up更新了\考试周第一天\肝完一个报告

本帖被以下淘专辑推荐:

推荐
wIInTer 2021-4-30 01:15:45 | 只看该作者
全局:
Mark一下,做笔记
回复

使用道具 举报

全局:
LZ太良心了,本new grad看你的帖子真的很长知识
回复

使用道具 举报

推荐
 楼主| 李浩泉 2020-6-16 08:16:33 | 只看该作者
全局:
本帖最后由 李浩泉 于 2020-6-16 09:04 编辑

10. 这道题比较费时间,一次需要创建4个business metrics,除了第一很简单,后面三个都需要花一些时间。表结构越简单的,往往题目越难。需要LAG()

Date Source: visit log table
date,                visitor_ID
2020-03-15        545468
2020-03-15        289320
.....
2020-03-20        841312

Ouput:
        date       total_visitor,visitor_gain,visitor_loss,total_new_visitors

2020-03-15       101                   0                    0                       0
2020-03-16       130                  29                   0                      29
2020-03-17       155                  25                   0                      54
2020-03-18       150                   0                    5                      49
2020-03-19       135                   0                   15                     34
2020-03-20       160                  25                   0                      59




  1. WITH CTE AS (
  2.   SELECT
  3.     date,
  4.     COUNT(visitor_ID) AS total_visitor,
  5.     LAG(COUNT(visitor_ID),1,0) OVER (ORDER BY date) AS lastday_total_visitor
  6.   FROM visit
  7.   GROUP BY date
  8. ),

  9. CTE1 AS (
  10.   SELECT
  11.     date,
  12.     total_visitor,
  13.     CASE WHEN total_visitor - lastday_total_visitor > 0 THEN total_visitor - lastday_total_visitor
  14.     ELSE 0 END AS visitor_gain,
  15.     CASE WHEN lastday_total_visitor - total_visitor > 0 THEN lastday_total_visitor - total_visitor
  16.     ELSE 0 END AS visitor_loss
  17.   FROM CTE
  18. ),

  19. CTE2 AS (
  20.   SELECT
  21.     date,
  22.     total_visitor,
  23.     visitor_gain,
  24.     visitor_loss,
  25.     visitor_gain - visitor_loss AS daily_change
  26.   FROM CTE1
  27. )

  28. SELECT
  29.     date,
  30.     total_visitor,
  31.     visitor_gain,
  32.     visitor_loss,
  33.     daily_change + (LAG((daily_change),1,0) OVER (ORDER BY date)) AS total_new_visitors
  34. FROM CTE2
复制代码










回复

使用道具 举报

🔗
 楼主| 李浩泉 2020-6-15 20:27:03 | 只看该作者
全局:
本帖最后由 李浩泉 于 2020-6-15 20:40 编辑

Purchase                           
+---------------+---------+         
| id                    | int          |
| Product_id      | int          |
| customer_id    | int          |
| purchase_date| datetime|
| quantity          | int          |
+---------------+---------+

Product

+-------------------+---------+
| Product_id           | int          |
| marketplace_id    | int          |
| discountinued_at | datetime|
| description           | varvhar |                                    
+-------------------+---------+

Q1: Find the number of the products available by market place.

  1. SELECT
  2. marketplace_id,
  3. COUTN(Product_id) AS [products available]
  4. FROM Product
  5. WHERE discountinued_at IS NULL OR discountinued_at > GETDATE()
复制代码


Product_id is the primary key in the table of Product, duplication will not be a question, so no need to add the "distinct".

discountinued_at IS NULL, it will return products that have no expire date
discountinued_at > GETDATE(), it will return products that will be expired in the future but currently are still available.


回复

使用道具 举报

🔗
 楼主| 李浩泉 2020-6-15 21:09:30 | 只看该作者
全局:
本帖最后由 李浩泉 于 2020-6-15 21:23 编辑

Purchase                           
+---------------+---------+         
| id                    | int          |
| Product_id      | int          |
| customer_id    | int          |
| purchase_date| datetime|
| quantity          | int          |
+---------------+---------+

Product

+-------------------+---------+
| Product_id           | int          |
| marketplace_id    | int          |
| discountinued_at | datetime|
| description           | varvhar  |                                    
+-------------------+---------+

Q2a. Find the top 3 and bottom 3 product sold in Dec 2019.
Q2b. Can you use other solution to replace windows function to improve the efficiency? For example: joins.

Q2a: Window Function


  1. WITH CTE AS (
  2.      SELECT Product.Product_id,
  3.      DENSE_RANK() OVER(ORDER BY ISNULL(SUM(quantity),0) ASC) AS RANK_ASC,
  4.      DENSE_RANK() OVER(ORDER BY ISNULL(SUM(quantity),0) DESC) AS RANK_DESC,
  5.      FROM Product LEFT JOIN Purchase ON Product.Product_id = Purchase.Product_id
  6.      WHERE YEAR(purchase_date) = 2019 AND MONTH(purchase_date) = 12         
  7.      GROUP BY Product.Product_id
  8. )


  9. SELECT
  10. Product_id AS [TOP 3],
  11. RANK_DESC
  12. FROM CTE
  13. WHERE RANK_DESC <= 3

  14. SELECT
  15. Product_id AS [BOTTOM 3],
  16. RANK_ASC
  17. FROM CTE
  18. WHERE RANK_ASC <= 3
复制代码





评分

参与人数 1大米 +3 收起 理由
霸王 + 3 给你点个赞!

查看全部评分

回复

使用道具 举报

🔗
 楼主| 李浩泉 2020-6-15 21:11:47 | 只看该作者
全局:
本帖最后由 李浩泉 于 2020-6-15 21:25 编辑

Q2b: Joins Solution (Not Sure if SQL allows order by in the where constraints, but in general you can select top 3 and bottom 3 distinct salaries and then join to the product by quantity )


  1. WITH CTE AS (
  2.      SELECT Product.Product_id,ISNULL(SUM(quantity),0) AS quantity
  3.      FROM Product LEFT JOIN Purchase ON Product.Product_id = Purchase.Product_id
  4.      WHERE YEAR(purchase_date) = 2019 AND MONTH(purchase_date) = 12
  5. )


  6. SELECT
  7. Product_id AS [TOP 3]
  8. FROM CTE
  9. WHERE quantity IN (  
  10.                    SELECT TOP3 DISTINCT quantity
  11.                    FROM CTE
  12.                    ORDER BY quantity DESC )

  13. SELECT
  14. Product_id AS [BOTTOM 3]
  15. FROM CTE
  16. WHERE quantity IN (  
  17.                    SELECT TOP3 DISTINCT quantity
  18.                    FROM CTE
  19.                    ORDER BY quantity ASC )
复制代码


回复

使用道具 举报

🔗
 楼主| 李浩泉 2020-6-15 21:38:15 | 只看该作者
全局:
本帖最后由 李浩泉 于 2020-6-15 21:43 编辑

通过@anna51100小姐姐的介绍,感觉亚麻厂的livecode就是一个共享桌面的虚拟白板,并不能运行和调试代码,所谓的技术面试,更看重的是理论基础,只要讲明白就可以通过。这和脸书的coderpad完全不一样,coderpad要运行和测试出结果,理论强代码运算不出结果也是不行的。我看过2018年的亚麻厂DE面试视频,好像那个时候用的还是hackerrank平台,和Leetcode差不多,不仅仅要出结果,而且后台还有多套test case。

用白板写Pseudocode,不会有硬伤,只要能说服面试官即可。坏处是,主观因素太多,感觉像写作文了。还是喜欢hackerrank,Leetcode,简单直接,不废话,对就对,错就是错。

微软的面试完全都是他们自己的软件,如果面试微软的BIE,DE,必须会用Power BI,SSIS等,更传统,看重的是具体软件工具的操作熟练程度。而不是考察基础的SQL,PYTHON,JAVA。

评分

参与人数 1大米 +3 收起 理由
barbel617 + 3 很有用的信息!

查看全部评分

回复

使用道具 举报

🔗
 楼主| 李浩泉 2020-6-15 21:54:20 | 只看该作者
全局:
Q3. Find the products in the marketplace 1 with at least 100 repeat customers in the last 1 month.
Repeat customers is a customer who buys same products on 2 consecutive days

  1. WITH CTE AS (
  2.   SELECT Product.Product_id,marketplace_id,customer_id,purchase_date
  3.   FROM Product LEFT JOIN Purchase ON Product.Product_id = Purchase.Product_id
  4.   WHERE marketplace_id = 1
  5.   AND DATEPART(m, DATEADD(m, -1, getdate())) = DATEPART(m, DATEADD(m, 0, purchase_date))
  6. )

  7. SELECT C1.Product_id
  8. FROM CTE C1 INNER JOIN CTE C2 ON C1.Product_id = C2.Product_id
  9. AND C1.customer_id = C2.customer_id AND DATEADD(DAY,1,C1.purchase_date) = C2.purchase_date
  10. GROUP BY C1.Product_id
  11. HAVING COUNT(C1.customer_id) >= 100
复制代码

评分

参与人数 1大米 +3 收起 理由
霸王 + 3 给你点个赞!

查看全部评分

回复

使用道具 举报

🔗
 楼主| 李浩泉 2020-6-15 21:54:36 | 只看该作者
全局:
本帖最后由 李浩泉 于 2020-6-15 22:04 编辑

Q3. Find the products in the marketplace 1 with at least 100 repeat customers in the last 1 month. Repeat customers is a customer who buys same products on 2 consecutive days。


@anna51100,面试的时候写成hard code。我们还是应该做好准备写dynamic。我记得我曾经的面试,当时就被中国程序员小哥哥面试官直接怼过,too much talking, too much questions, just focus on coding,do not waste time。

  1. WITH CTE AS (
  2.   SELECT DISTINCT Product.Product_id,customer_id,purchase_date
  3.   FROM Product LEFT JOIN Purchase ON Product.Product_id = Purchase.Product_id
  4.   WHERE marketplace_id = 1
  5.   AND DATEPART(m, DATEADD(m, -1, getdate())) = DATEPART(m, DATEADD(m, 0, purchase_date))
  6. )

  7. SELECT C1.Product_id
  8. FROM CTE C1 INNER JOIN CTE C2 ON C1.Product_id = C2.Product_id
  9. AND C1.customer_id = C2.customer_id AND DATEADD(DAY,1,C1.purchase_date) = C2.purchase_date
  10. GROUP BY C1.Product_id
  11. HAVING COUNT(C1.customer_id) >= 100
复制代码





回复

使用道具 举报

🔗
 楼主| 李浩泉 2020-6-15 22:31:04 | 只看该作者
全局:
本帖最后由 李浩泉 于 2020-6-15 22:32 编辑

Q4. We have customers, their total purchases (dollar value) in last year (2019). As a BIE, what visualization would you do to report to stakeholders about this.

Correct me if I am wrong. We have 2 business metrics, one is the # of customers, the other is the # of sales in 2019. If I would present the two metrics to the management, I could

either

divide the total number of customers, for example let's say 1 million, into 10 subgroups, group 1 from 0 - 100K, group 2 from 100K - 200K and so on. To show the distribution of sales in different subgroups in a bar chart. According to the 20-80 rules, we can see how much our top 20% customers contribute the sales, is it over 80% or below. So we can focus on our top tier customer segmentation to leverage more resource in the next fiscal year.  

or

divide the total sales, for example let's say 1 billion, into 5 groups , group A is from 0 - 200M, group by B is from 200M - 400M, by number of customers. It will show the distribution of customers by sales. if possible, we can also add gender or age dimensions to illustrate the full picture more clear.

评分

参与人数 1大米 +3 收起 理由
霸王 + 3 给你点个赞!

查看全部评分

回复

使用道具 举报

🔗
 楼主| 李浩泉 2020-6-16 02:44:29 | 只看该作者
全局:
本帖最后由 李浩泉 于 2020-6-16 02:45 编辑

刚才发题库的帖子被管理员移到面经版块了,我现在不能更新了,所以把题库放在这里:

亚麻SQL面试题库 #5

5a. find out the median price of sold products in Dec. 2019

  1. SELECT AVG(unit_price) AS Median
  2. FROM (
  3. SELECT DISTINCT
  4. product_id,
  5. unit_price,
  6. ROW_NUMBER() OVER(ORDER BY unit_price DESC) AS RN,
  7. COUNT(ID) OVER() AS COUNTS
  8. FROM orders
  9. WHERE YEAR(Orders_date) = 2019 AND MONTH(Orders_date) = 12 ) T
  10. WHERE RN BETWEEN COUNTS/2 AND COUNTS/2+1
复制代码


评分

参与人数 1大米 +3 收起 理由
霸王 + 3 给你点个赞!

查看全部评分

回复

使用道具 举报

🔗
 楼主| 李浩泉 2020-6-16 05:24:05 | 只看该作者
全局:

5b. find out the product with the highest unit price based on the most recent completed orders

  1. WITH CTE AS (
  2.   SELECT product_id,MAX(order_date) AS Most_Recent_Date
  3.   FROM orders
  4.   WHERE status = 'Completed'
  5.   GROUP BY product_id )

  6. SELECT product_id,unit_price
  7. FROM (
  8. SELECT CTE.product_id,unit_price,
  9.        DENSE_RANK() OVER(ORDER BY unit_price DESC) AS RK
  10. FROM CTE INNER JOIN orders ON CTE.product_id = orders.product_id AND CTE.Most_Recent_Date = orders.order_date ) T
  11. WHERE RK = 1
复制代码


回复

使用道具 举报

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

本版积分规则

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