Codes

You might also like

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

ALTER VIEW daily_Customers AS

SELECT c.FirstName, c.LastName, c.EmailAddress, s.Date, s.SalesAmount


FROM Customers c
JOIN Sales s ON c.CustomerID = s.CustomerID
WHERE s.Date = CURDATE()
ORDER BY c.DateOfBirth;

CREATE INDEX idx_customers ON Customers (CustomerID);


CREATE INDEX idx_sales ON Sales (SalesID);
CREATE INDEX idx_products ON Products (ProductID);

CREATE VIEW daily_Customers AS


SELECT c.FirstName, c.LastName, s.Date, s.SalesAmount
FROM Customers c
JOIN Sales s ON c.CustomerID = s.CustomerID
WHERE s.Date = CURDATE()
ORDER BY c.DateOfBirth;

SELECT c.FirstName, c.LastName, c.DateOfBirth, SUM(s.SalesAmount) AS TotalSales


FROM Customers c
JOIN Sales s ON c.CustomerID = s.CustomerID
GROUP BY c.CustomerID
ORDER BY TotalSales DESC;

SELECT FirstName, LastName, SalesAmount


FROM Customers
WHERE SalesAmount > 0;

You might also like