0% found this document useful (0 votes)
0 views

Q1

The document contains a series of SQL queries designed to retrieve various customer and order-related information from a database. It includes queries to find customers who have placed orders, details of orders along with customer information, and customers who have never placed an order, among others. Each query is commented with its purpose and intended output.

Uploaded by

chaitanya252533
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)
0 views

Q1

The document contains a series of SQL queries designed to retrieve various customer and order-related information from a database. It includes queries to find customers who have placed orders, details of orders along with customer information, and customers who have never placed an order, among others. Each query is commented with its purpose and intended output.

Uploaded by

chaitanya252533
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

--Q1)find all customers who have placed an order.

/* SELECT DISTINCT *

FROM Customers c

JOIN Orders o ON c.customer_id = o.customer_id; */

--Q2) List the orders along with customer details.

/* SELECT *, c.first_name, c.last_name, c.age, c.country

FROM Orders o

JOIN Customers c ON o.customer_id = c.customer_id; */

-- Q3)Find customers who have never placed an order.

/* SELECT *

FROM Customers c

LEFT JOIN Orders o ON c.customer_id = o.customer_id

WHERE o.customer_id IS NULL;*/

-- Q4)Retrieve all customers from the UK.

/* SELECT * FROM Customers WHERE country = 'UK'; */

-- Q5) Get the total number of orders placed by each customer.

/* SELECT c.customer_id, c.first_name, c.last_name, COUNT(o.order_id) AS total_orders

FROM Customers c

LEFT JOIN Orders o ON c.customer_id = o.customer_id

GROUP BY c.customer_id, c.first_name, c.last_name;*/

-- Q6) List customers who ordered a Keyboard and their shipping status.

/* SELECT DISTINCT *, s.status

FROM Customers c

JOIN Orders o ON c.customer_id = o.customer_id

LEFT JOIN Shipping s ON c.customer_id = s.customer

WHERE o.item = 'Keyboard';*/

-- Q7) Retrieve the total revenue generated by each customer.

/* SELECT c.customer_id, c.first_name, c.last_name, SUM(o.amount) AS total_revenue

FROM Customers c

JOIN Orders o ON c.customer_id = o.customer_id


GROUP BY c.customer_id, c.first_name, c.last_name;*/

-- Q8) Find customers whose orders have been delivered.

/* SELECT DISTINCT *

FROM Customers c

JOIN Shipping s ON c.customer_id = s.customer

WHERE s.status = 'Delivered';*/

-- Q9) Find customers who ordered both a Keyboard and a Mouse.

/* SELECT *

FROM Customers c

JOIN Orders o1 ON c.customer_id = o1.customer_id AND o1.item = 'Keyboard'

JOIN Orders o2 ON c.customer_id = o2.customer_id AND o2.item = 'Mouse'; */

-- Q10) Find the total revenue per country.

/* SELECT c.country, SUM(o.amount) AS total_revenue

FROM Customers c

JOIN Orders o ON c.customer_id = o.customer_id

GROUP BY c.country; */

-- Q11) Find customers who have placed orders but have no shipping status.

/* SELECT DISTINCT *

FROM Customers c

JOIN Orders o ON c.customer_id = o.customer_id

LEFT JOIN Shipping s ON c.customer_id = s.customer

WHERE s.customer IS NULL; */

-- Q12) Find customers who placed an order but spent less than $500.

SELECT c.customer_id, c.first_name, c.last_name, SUM(o.amount) AS total_spent

/* FROM Customers c

JOIN Orders o ON c.customer_id = o.customer_id

GROUP BY c.customer_id, c.first_name, c.last_name

HAVING SUM(o.amount) < 500; */

You might also like