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! 💡
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
-- 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;
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??
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! 💡
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
Great work ! Keep learning ❤️
Nice and better solution than using 'where' and subqueries on this problem!
Yes, absolutely! 💯
Thanks bhaiya.
-- 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;
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??
If there is product key 7 then total count in Product table will become 3, it won't be 2
can you please make video on pandas 30 days leetcode QUESTION
Sure , till then complete the Introduction to Pandas Playlist ( 15 questions)..
Great Sir !!
Thanks and keep learning 😃
thanks
Glad it was helpful 💐