From db32ed79830d3af6886a87626e762e106d2e9117 Mon Sep 17 00:00:00 2001 From: Omid Reza Heidari Date: Mon, 12 Feb 2024 15:40:51 -0500 Subject: [PATCH] Update Lecture.sql --- static/Session04/Lecture.sql | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/static/Session04/Lecture.sql b/static/Session04/Lecture.sql index cde50512..76d8c5fa 100644 --- a/static/Session04/Lecture.sql +++ b/static/Session04/Lecture.sql @@ -1,7 +1,10 @@ +# Use the database use comp353lab; +# drop the target tables if exists drop table if exists customers, orders; +# Creating of the tables + Insertion of the date to them create table customers( id int primary key auto_increment, first_name varchar(50), @@ -37,45 +40,56 @@ insert into orders(customer_id, amount, created_at, ship_to) (2, 500, '1999-02-02 22:00:00.000000', 'Iran'), (1, 100, '2002-02-02 09:00:00.000000', 'Denmark'); +# Eliminate all of the customer with lower balance than 1500 delete from customers where customers.balance<1500; +# Update all of the Customers with country of Denmark to Turkey update customers set customers.country = 'Turkey' where customers.country = 'Denmark'; -select * +# See all of the customers +select customers.id, customers.country from customers; -select * +# Fetch all of the order with id of 1, 3, or 6 +select orders.id, orders.amount, orders.ship_to from orders where id in (1, 3, 6); +# Alternative way to implement the above command select * from orders where id=1 or id=3 or id=6; +# Fetch all of the countries (orders and customers tables) select customers.country from customers union select orders.ship_to from orders; -select orders.amount +# Fetch all of the order with amount in range of 350 and 550 +select orders.id, orders.amount from orders where amount between 350 and 550; - -select * +# See all of the customers +select customers.id, customers.country, customers.first_name, customers.last_name from customers; -select * +# Set limit +select customers.id, customers.country, customers.first_name, customers.last_name from customers limit 2; -select * +# Set Limit with offset +select customers.id, customers.country, customers.first_name, customers.last_name from customers limit 2 offset 1; + +