Top SQL Interview Q&A for Data Scientists

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ส.ค. 2024

ความคิดเห็น • 11

  • @zijiaoli906
    @zijiaoli906 7 หลายเดือนก่อน

    Great summary! One minor correction is necessary I think for the last solution: in the window function of the 1st CTE, we should add pref_delivery_date to the order by clause as 1 user could have 2 orders with pre_delivery_date J and J+3 on order date J (first day) for example, without pref_delivery_date in the order by clause, it could randomly assign order with delivery date J+3 as row no 1 and thus not consider this as immediate order whereas it should have been !

  • @jasonsun7527
    @jasonsun7527 ปีที่แล้ว +5

    We should be very careful when using AVG(CASE WHEN...), because it will count duplicate values for denominator and it could be a problem when total count has duplicates but the question doesn't want duplicates in the denominator. For example, we are dealing with order table (duplicate values for customer column) and the question is asking for the percentage of certain customers.

    • @jasonsun7527
      @jasonsun7527 ปีที่แล้ว

      A great solution, as shown by Emma, is using window function and order_rnk=1 to guarantee denominator having unique values ( distinct customers).

    • @davidskarbrevik
      @davidskarbrevik ปีที่แล้ว

      Good point, although in the second example it’s a requirement to not have duplicates since a customer can only have 1 first order

    • @chrisanderson4387
      @chrisanderson4387 ปีที่แล้ว +1

      Use sum, div0 and distinct

  • @rezarafieirad
    @rezarafieirad ปีที่แล้ว

    great video, please share some insights on how to answer Guesstimates

  • @pratikmad4u
    @pratikmad4u ปีที่แล้ว

    customer_id 3 also had an immediate delivery right? since the dates are same in both columns of (order_date and pref_delivery_date) = 2019-10-12 or did i miss something?

    • @user-wb7vz8fx9k
      @user-wb7vz8fx9k ปีที่แล้ว +2

      No, because imediate delivery also means the dates of the columns is equal on their first delivery, but in the case of customer id 3, it is his second delivery.

    • @pratikmad4u
      @pratikmad4u ปีที่แล้ว

      @@user-wb7vz8fx9k Thanks , I didn't notice that 2019-10-12 was customer_id 3's second order, first being on 2019-10-09

  • @emma_ding
    @emma_ding  ปีที่แล้ว

    Many of you have asked me to share my presentation notes, and now… I have them for you! Download all the PDFs of my Notion pages at www.emmading.com/get-all-my-free-resources. Enjoy!

    • @AMohanKumar031
      @AMohanKumar031 9 หลายเดือนก่อน

      Thanks a Ton Emma Ding.