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

Ioannis Eleftheriadis

Βάση δεδομένων SQL για την εταιρία:


1. Customers (Customer_id: integer, Name: string , Address: string , Email: string,
Phone: string)
Εντολή:
#1. Customers (Customer_id: integer, Name: string , Address: string , Email: string, Phone: string)
CREATE TABLE Customers (
Customer_id int,
name varchar(255),
address varchar(255),
Email varchar(255),
phone varchar(255)
);

2. Orders (order_no: integer, customet_id: integer, date: date, total_cost: currency)


#2. Orders (order_no: integer, customer_id: integer, date: date, total_cost: currency)
CREATE TABLE Orders (
order_no int,
customer_id int,
date_order date,
total_cost currency
);
Ioannis Eleftheriadis

3. Products (product_id: integer, product_name: string, description: string, price:


currency, quantity: integer)
#3. Products (product_id: integer, product_name: string, description: string, price: currency, quantity:
integer)
CREATE TABLE Products (
product_id int,
product_name varchar(255),
description varchar(255),
price currency,
quantity int
);

4. Order_details (product_id, order_no, items)


#4. Order_details (product_id, order_no, items)
CREATE TABLE Order_details (
product_id int,
order_no int,
items int
);
Ioannis Eleftheriadis

Εισαγωγή δεδομένων:
Customers:
INSERT INTO Customers(Customer_id ,Name, Address, Email, Phone)
VALUES (1, "Maria Ioannou", "123 Main Str", "marioan@email.com", "555-1234");
INSERT INTO Customers(Name, Address, Email, Phone)
VALUES (2, ‘Ioannis Ioannou’, ‘223 Main Str’, ‘ioannisioan@email.com’, ‘666-1234’);

INSERT INTO Customers(Name, Address, Email, Phone)


VALUES (3,‘Antonis Ioannou’, ‘333 Main Str’, ‘antonisioan@email.com’, ‘777-1234’);

INSERT INTO Customers(Name, Address, Email, Phone)


VALUES (4,‘Konstantinos Ioannou’, ‘433 Main Str’, ‘konstaioan@email.com’, ‘888-1234’);
Orders:
INSERT INTO Orders(order_no, customer_id, date_order, total_cost)
VALUES (1, 1111, ?, ?);

INSERT INTO Orders(order_no, customer_id, date_order, total_cost)


VALUES (2, 1112, ?, ?);

INSERT INTO Orders(order_no, customer_id, date_order, total_cost)


VALUES (3, 1113, ?, ?);
INSERT INTO Orders(order_no, customer_id, date_order, total_cost)
VALUES (4, 1114, ?, ?);
Ioannis Eleftheriadis

Products:

INSERT INTO Products(product_id, product_name, description, price, quantity)


VALUES (11111111, ioannis1, ximos, 1, 10);

INSERT INTO Products(product_id, product_name, description, price, quantity)


VALUES (11111112, ioannis2, pagoto, 3, 5));

INSERT INTO Products(product_id, product_name, description, price, quantity)


VALUES (11111113, ioannis3, nero, 0.50, 100);

INSERT INTO Products(product_id, product_name, description, price, quantity)


VALUES (11111114, ioannis4, krouasan, 0.90, 20);
Ioannis Eleftheriadis

Order_details:

INSERT INTO Order_details(product_id, order_no, items)


VALUES (Products.product_id, Orders.order_no, ximos;

INSERT INTO Order_details(product_id, order_no, items)


VALUES (Products.product_id, Orders.order_no, pagoto);

INSERT INTO Order_details(product_id, order_no, items)


VALUES (Products.product_id, Orders.order_no, nero);

INSERT INTO Order_details(product_id, order_no, items )


VALUES (Products.product_id, Orders.order_no, krouasan);

Να εμφανίζει τους πελάτες που έκαναν έστω και μια παραγγελία


Ioannis Eleftheriadis

SELECT Customers.customer_id,Customers.name,Order_details.order_no
FROM Customers,Order_details,Orders
WHERE Customers.customer_id = Orders.customer_id AND Order_details.order_no = Orders.order_no;

Να βρίσκει το σύνολο (total revenue) της εταιρείας που έπιασε το 2021 (δλδ: από τις
1/1/2021 μέχρι τις 31/12/2021)  με το SELECT SUM
SELECT SUM(Products.price*Products.quantity)
FROM Orders,Customers,Products,Order_details
WHERE Orders.date_order >= 1/1/2021
AND Orders.date_order <= 31/12/2021
AND Order_details.product_id = Products.product_ID
AND Order_details.order_no = Orders.order_no
AND Customers.Customer_id = Orders.customer_id;

Να εμφανίζει το πιο δημοφιλές προϊόν της εταιρείας το 2022. (δηλαδή αυτό με τις
περισσότερες πωλήσεις το 2022)
SELECT MAX(Products.quantity), Products.description
Ioannis Eleftheriadis

FROM Orders,Customers,Products,Order_details
WHERE Order_details.product_id = Products.product_ID
AND Order_details.order_no = Orders.order_no
AND Customers.Customer_id = Orders.customer_id;

Να εμφανίζει τα προϊόντα που η ποσότητα έπεσε κάτω από 5.


SELECT Products.quantity, Products.description
FROM Orders,Customers,Products,Order_details
WHERE Order_details.product_id = Products.product_ID
AND Order_details.order_no = Orders.order_no
AND Customers.Customer_id = Orders.customer_id;
Δεν εχω προιοντα με ποσοτητα κατω από 5 εχω με 5 ακριβως.
Ioannis Eleftheriadis

You might also like