0% found this document useful (0 votes)
8 views2 pages

Questions

Uploaded by

Ghanashyam Ahire
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Questions

Uploaded by

Ghanashyam Ahire
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Q.

Retrieve the names of customers who have purchased products with a price higher than the
average price of products in each category:

SELECT DISTINCT c.name

FROM customers c

JOIN sales s ON c.cust_id = s.cust_id

JOIN products p ON s.product_id = p.product_id

WHERE p.price > (SELECT AVG(price)

FROM products p2

WHERE p2.P_Category = p.P_Category);

Q. Find the products that have been sold at least twice and list their details:

SELECT p.*

FROM products p

WHERE p.product_id IN (

SELECT product_id

FROM sales

GROUP BY product_id

HAVING COUNT(*) >= 2);

Q. Retrieve the names and emails of customers who have not made any purchases:

SELECT c.name, c.email

FROM customers c

WHERE c.cust_id NOT IN (

SELECT DISTINCT Cust_ID

FROM sales);

Q.Find the total sales amount for each customer in the last month:

SELECT c.name, SUM(s.Sales_Amount) AS total_sales

FROM customers c

JOIN sales s ON c.cust_id = s.cust_id


WHERE s.Sales_Date >= DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH)

GROUP BY c.cust_id;

You might also like