You🤓 it is so Easy(AASAN HAI?) | Oracle | MySQL | Postgre |
ApproachUSING With clause:-WITH CTEName AS (
SELECT ... -- Query that creates the temporary result set
)
SELECT ...
FROM CTEName
WHERE ...;AlternateNoteBe aware
# Approach
USING With clause:-

WITH CTEName AS (
    			SELECT ... -- Query that creates the temporary result set
		)
		SELECT ...
		FROM CTEName
		WHERE ...;

# Alternate
    -- for all : OracleSQL | MySQL | PostgreSQL 
    SELECT customer_id
    FROM Customer
    GROUP BY customer_id
    HAVING COUNT(DISTINCT product_key) = 
    (SELECT COUNT(DISTINCT product_key) FROM Product);


```
```
# Note
Be aware of using 'DISTINCT' 

COUNT(DISTINCT product_key): Ensures that we only count unique product purchases per customer and properly handles cases where some rows might have NULL values.


# Code
```OracleSQL []
/* Write your PL/SQL query statement below */

WITH TotalProducts AS (
    SELECT COUNT(DISTINCT product_key) AS total_product_count FROM Product
)
SELECT customer_id
FROM Customer
GROUP BY customer_id
HAVING COUNT(DISTINCT product_key) = (SELECT total_product_count FROM TotalProducts);

```

```MySQL []

WITH TotalProducts AS (
    SELECT COUNT(DISTINCT product_key) AS total_product_count FROM Product
)
SELECT customer_id
FROM Customer
GROUP BY customer_id
HAVING COUNT(DISTINCT product_key) = (SELECT total_product_count FROM TotalProducts);

```

``` PostgreSQL []
WITH TotalProducts AS (
    SELECT COUNT(DISTINCT product_key) AS total_product_count FROM Product
)
SELECT customer_id
FROM Customer
GROUP BY customer_id
HAVING COUNT(DISTINCT product_key) = (SELECT total_product_count FROM TotalProducts);

```

# do Upvote 👨🏾
it will help me to feed my cat🐱

hope it will help🫂

https://leetcode.com/list/o2qifkts
['MySQL', 'Oracle', 'PostgreSQL']