D22
D22
use D2
--Question 1:
--Write an SQL query to retrieve the names of all customers who have placed orders
in Paris.
SELECT C.Name
FROM Customerss C
JOIN Orders O ON C.ID = O.Customer_ID
WHERE C.City = 'Paris';
--Question 2:
--Write an SQL query to retrieve the total order amount for each city.
--Question 3:
--Write an SQL query to retrieve the customer name and order details for all orders
placed in 2022.
SELECT C.Name, O.Order_ID, O.Order_Date, O.Amount
FROM Customerss C
JOIN Orders O ON C.ID = O.Customer_ID
WHERE O.Order_Date >= '2022-01-01' AND O.Order_Date < '2023-01-01';
--Question 4:
--Write an SQL query to retrieve the customer who has placed the highest total
amount of orders.
--Question 5:
Write an SQL query to retrieve the customer names who have not placed any orders.
SELECT C.Name
FROM Customerss C
LEFT JOIN Orders O ON C.ID = O.Customer_ID
WHERE O.Order_ID IS NULL;
Q)Question 1:
Add two new columns to the "Customerss" table: "Email" (VARCHAR(100)) and "Phone"
(VARCHAR(20)).
Insert two new records into the "Customerss" table with the following details:
Write an SQL query to retrieve the customer names and their respective order
details (order ID, order date, and amount) for customers who have placed orders.
Write an SQL query to retrieve the customer names, their respective order dates,
and the total order amount for customers who have placed orders in Berlin.
Solution:
sql
Copy
SELECT C.Name, O.Order_Date, SUM(O.Amount) AS Total_Order_Amount
FROM Customerss C
JOIN Orders O ON C.ID = O.Customer_ID
WHERE C.City = 'Berlin'
GROUP BY C.Name, O.Order_Date;