Customers Who Bought All Products | Leetcode 1045 | Crack SQL Interviews in 50 Qs

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

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

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

    Hey there! 👋 For more interesting content, tutorials, and updates, Feel free to connect with me on
    Instagram Handles :-
    @createwithchirag - instagram.com/createwithchirag/
    @learn.with.chirag - instagram.com/learn.with.chirag/
    LinkedIn: www.linkedin.com/in/chirag-sehgal-9200111b8/
    Let's stay connected and keep the creativity flowing! 💡

  • @ranitmandal6393
    @ranitmandal6393 6 หลายเดือนก่อน +3

    select c.customer_id
    from Customer as c
    join Product as p
    group by customer_id
    having count( distinct c.product_key)=count( distinct p.product_key)
    using joins

    • @learnwithchirag
      @learnwithchirag  6 หลายเดือนก่อน

      Great work ! Keep learning ❤️

  • @nimbu_03
    @nimbu_03 10 หลายเดือนก่อน

    Nice and better solution than using 'where' and subqueries on this problem!

  • @apoorvpradhan5125
    @apoorvpradhan5125 2 หลายเดือนก่อน

    Thanks bhaiya.

  • @ChandanSahoo-yi2tv
    @ChandanSahoo-yi2tv 4 หลายเดือนก่อน

    -- both the select statements are correct
    with cte as (
    select c.customer_id,count(distinct p.product_key) total_bought
    from Customer c
    left join Product p on c.product_key = p.product_key
    group by c.customer_id
    ),
    cte2 as (
    select distinct count(product_key) as total_products from Product
    )
    -- SELECT c.customer_id FROM cte c CROSS JOIN cte2 c2 WHERE c.total_bought = c2.total_products;
    SELECT c.customer_id FROM cte c, cte2 c2 WHERE c.total_bought = c2.total_products;

  • @anonymous_hecklar
    @anonymous_hecklar 3 หลายเดือนก่อน

    Here we are equating count(distinct product_key) = (
    SELECT count(product_key)
    from Product
    )
    but suppose a customer buy product key 5 and 7 still its count is 2 but product keys given in product table are 5 and 6
    So according to question he has not buy all the items??

    • @shraddhapawar454
      @shraddhapawar454 20 วันที่ผ่านมา

      If there is product key 7 then total count in Product table will become 3, it won't be 2

  • @aishwaryaarya4554
    @aishwaryaarya4554 3 หลายเดือนก่อน

    can you please make video on pandas 30 days leetcode QUESTION

    • @learnwithchirag
      @learnwithchirag  3 หลายเดือนก่อน

      Sure , till then complete the Introduction to Pandas Playlist ( 15 questions)..

  • @akhilpratapsingh3223
    @akhilpratapsingh3223 10 หลายเดือนก่อน

    Great Sir !!

    • @learnwithchirag
      @learnwithchirag  10 หลายเดือนก่อน

      Thanks and keep learning 😃

  • @kushalagrawal3048
    @kushalagrawal3048 4 หลายเดือนก่อน

    thanks

    • @learnwithchirag
      @learnwithchirag  4 หลายเดือนก่อน +1

      Glad it was helpful 💐