0% found this document useful (0 votes)
7 views3 pages

DATABASE CustomerOrderDB

The document outlines the creation of a database named CustomerOrderDB, including the definition of two tables: Customer and Order, with their respective fields and relationships. It includes sample data insertion for customers and orders, as well as several SQL queries to retrieve specific information from the database. The queries demonstrate filtering, sorting, and aggregation of order data based on customer attributes.

Uploaded by

sreya.haldar
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)
7 views3 pages

DATABASE CustomerOrderDB

The document outlines the creation of a database named CustomerOrderDB, including the definition of two tables: Customer and Order, with their respective fields and relationships. It includes sample data insertion for customers and orders, as well as several SQL queries to retrieve specific information from the database. The queries demonstrate filtering, sorting, and aggregation of order data based on customer attributes.

Uploaded by

sreya.haldar
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

CREATE DATABASE CustomerOrderDB;

USE CustomerOrderDB;

CREATE TABLE Customer (

CustomerID VARCHAR(10) PRIMARY KEY,

CustomerName VARCHAR(50),

City VARCHAR(50),

MobileNo BIGINT );

CREATE TABLE Order(

OrderID VARCHAR(10) PRIMARY KEY,

OrderDate DATE,

OrderAmt INT,

CustomerID VARCHAR(10),

FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID) );

INSERT INTO Customer VALUES (‘C111’, ‘Abhishek’, ‘Ahmedabad’, 9999999999);

INSERT INTO Customer VALUES(‘C132’, ‘Bhavik’, ‘Anand’, 7799779977);

INSERT INTO Customer VALUES (‘C135’, ‘Chandani’, ‘Baroda’, 8856895485);

INSERT INTO Customer VALUES (‘C145’, ‘Dhara’, ‘Ahmedabad’, 7456879652);

INSERT INTO Customer VALUES (‘C121’, ‘Divya’, ‘Anand’, 9015123569);

INSERT INTO Order VALUES (‘O111’, ‘2022-04-15’, 1500, ‘C111’);

INSERT INTO Order VALUES(‘O112’, ‘2022-05-20’, 1800, ‘C121’);

INSERT INTO Order VALUES (‘O113’, ‘2022-05-31’, 1000, ‘C199’);

INSERT INTO Order VALUES (‘O131’, ‘2022-06-12’, 1400, ‘C135’);

(i)
SELECT CustomerID, CustomerName, OrderAmt FROM Customer NATURAL JOIN Order

WHERE City = 'Ahmedabad';

Output:

(ii)

SELECT * FROM Order ORDER BY OrderAmt DESC;

Output:

(iii)
SELECT OrderID, OrderDate, CustomerName, MobileNo FROM Customer NATURAL JOIN
Order WHERE CustomerName LIKE '%h%' AND CustomerName LIKE '%k';

Output:

(iv)

SELECT City, SUM(OrderAmt) AS TotalOrderAmt FROM Customer NATURAL JOIN Order


GROUP BY City;

Output:

You might also like