'عبد الرحمن ديرية نظم 2'

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

‫عبد الرحمن ديرية‬

Absolutely, here are the SQL queries for the e-commerce platform schema you
provided:
1. Retrieve all customers who registered after January 1, 2023:
SQL
SELECT *
FROM Customers
WHERE RegistrationDate > '2023-01-01';

2. List the names and prices of all products in the 'Electronics'


category:
SQL
SELECT ProductName, Price
FROM Products
WHERE Category = 'Electronics';

3. Retrieve a list of orders along with the customer's first and last
name:
SQL
SELECT o.OrderID, o.OrderDate, o.TotalAmount, c.FirstName,
c.LastName
FROM Orders o
INNER JOIN Customers c ON o.CustomerID = c.CustomerID;

4. Get a list of products along with the total quantity ordered for each.
Only include products that have been ordered at least once:
SQL
SELECT p.ProductID, p.ProductName, SUM(od.Quantity) AS
TotalQuantityOrdered
FROM Products p
INNER JOIN OrderDetails od ON p.ProductID = od.ProductID
GROUP BY p.ProductID, p.ProductName
HAVING SUM(od.Quantity) > 0;

Here's a breakdown of each query:


• Query 1: We use SELECT * to retrieve all columns from the Customers
table. The WHERE clause filters the results to only include customers where
the RegistrationDate is greater than January 1, 2023.
• Query 2: We select ProductName and Price from the Products table. The
WHERE clause filters the results to only include products where the

Category is equal to 'Electronics'.

• Query 3: We use an INNER JOIN between the Orders and Customers


tables to combine data based on the CustomerID foreign key. This allows
us to retrieve order information (OrderID, OrderDate, and TotalAmount)
along with the customer's FirstName and LastName from the Customers
table.
• Query 4: We use an INNER JOIN between the Products and
OrderDetails tables to connect product information with order details. We
then use GROUP BY to group products together and SUM to calculate the
total quantity ordered for each product. The HAVING clause filters the
results to only include products with a total quantity greater than 0
(meaning they have been ordered at least once).

You might also like