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

k1

The document contains various SQL queries for managing and retrieving data from a database, including selecting orders by customer email, counting orders by date, and filtering customers by last name. It also includes commands for creating and altering tables, inserting data, and performing joins between tables. Additionally, it demonstrates grouping and sorting data based on specific criteria.

Uploaded by

jabikoi314
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)
2 views

k1

The document contains various SQL queries for managing and retrieving data from a database, including selecting orders by customer email, counting orders by date, and filtering customers by last name. It also includes commands for creating and altering tables, inserting data, and performing joins between tables. Additionally, it demonstrates grouping and sorting data based on specific criteria.

Uploaded by

jabikoi314
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/ 3

list orders placed by customers with an email ending in @example.com.

SELECT Orders.*FROM OrdersJOIN Customers ON Orders.c_id =


Customers.c_idWHERE Customers.email LIKE '%@example.com';

Count the number of orders placed on each date.


SELECT order_date, COUNT(*) AS OrderCount
FROM Orders
GROUP BY order_date;

Find the total number of orders placed by c_id 101.


SELECT COUNT(*) AS TotalOrders FROM Orders WHERE c_id = 101;

Select customers whose last name contains the letter "a".


SELECT * FROM Customers WHERE last_name LIKE '%a%';

customer table have cid,first name ,last name,email and order table
got oid,cid,order date and total amount creat 2 table
CREATE DATABASE databasename;

ALTER TABLE table_name


ADD column_name datatype;

CREATE TABLE Persons (


ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
PRIMARY KEY (ID)
);

CREATE TABLE Orders (


OrderID int NOT NULL,
OrderNumber int NOT NULL,
PersonID int,
PRIMARY KEY (OrderID),
FOREIGN KEY ( PersonID) REFERENCES persons(ID) );

INSERT INTO Customers (CustomerName, ContactName, Address, City,


PostalCode, Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');

UPDATE Customers
SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
WHERE CustomerID = 1;

SELECT CustomerName, City FROM Customers;

Select all customers from Mexico:


SELECT * FROM Customers
WHERE Country='Mexico';

Sort the products by price:


SELECT * FROM Products
ORDER BY Price;

Select all customers from Spain that starts with the letter 'G':
SELECT *
FROM Customers
WHERE Country = 'Spain' AND CustomerName LIKE 'G%';

SELECT * FROM Customers


WHERE Country = 'Spain' AND (CustomerName LIKE 'G%' OR CustomerName
LIKE 'R%');
Select customers that does not start with the letter 'A':
SELECT * FROM Customers
WHERE CustomerName NOT LIKE 'A%';

Join Products and Categories with the INNER JOIN keyword:


SELECT ProductID, ProductName, CategoryName
FROM Products
INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID;

SELECT City FROM Customers


UNION
SELECT City FROM Suppliers
ORDER BY City;

SELECT COUNT(CustomerID), Country


FROM Customers
GROUP BY Country;

SELECT * FROM Customers WHERE last_name LIKE '%a%';

You might also like