Skip to content

Commit

Permalink
Update slides and sql files
Browse files Browse the repository at this point in the history
  • Loading branch information
omid-reza committed Feb 12, 2024
1 parent db32ed7 commit f48919a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
Binary file modified docs/Session04/Lecture.pdf
Binary file not shown.
45 changes: 38 additions & 7 deletions docs/Session04/Lecture.sql
Original file line number Diff line number Diff line change
@@ -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),
Expand All @@ -15,6 +18,7 @@ create table customers(
insert into customers(first_name, last_name, email, password, country, balance) values
('Omid Reza', 'Heidari', 'omid.orh@gmail.com', 'password1', 'Iran', 2000),
('Ali', 'Amiri', 'ali@gmail.com', 'password2', 'Canada', 3000),
('Ali', 'Ahmad', 'ali.ahmad@gmail.com', 'password2', 'Iraq', 4500),
('John', 'Nash', 'nash@gmail.com', 'password3', 'Denmark', 1400),
('Pari', 'Amin', 'pr.am@gmail.com', 'password4', 'Iran', 4200),
('David', 'Ahmad', 'dmp.mmd@gmail.com', 'password5', 'Canada', 300);
Expand All @@ -37,45 +41,72 @@ 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 *
# Like command (with wildcard)
select customers.id, customers.first_name, customers.last_name ,customers.country
from customers
where country like '%da';

select customers.id, customers.first_name, customers.last_name ,customers.country
from customers
where country like 'Ir%';

select customers.id, customers.first_name, customers.last_name ,customers.country
from customers
where country like 'Ir_n';

# Like command (without wildcard)
select customers.id, customers.first_name, customers.last_name ,customers.country
from customers
where country like 'Canada';

# 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;

Binary file modified static/Session04/Lecture.pdf
Binary file not shown.
23 changes: 20 additions & 3 deletions static/Session04/Lecture.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ create table customers(
insert into customers(first_name, last_name, email, password, country, balance) values
('Omid Reza', 'Heidari', 'omid.orh@gmail.com', 'password1', 'Iran', 2000),
('Ali', 'Amiri', 'ali@gmail.com', 'password2', 'Canada', 3000),
('Ali', 'Ahmad', 'ali.ahmad@gmail.com', 'password2', 'Iraq', 4500),
('John', 'Nash', 'nash@gmail.com', 'password3', 'Denmark', 1400),
('Pari', 'Amin', 'pr.am@gmail.com', 'password4', 'Iran', 4200),
('David', 'Ahmad', 'dmp.mmd@gmail.com', 'password5', 'Canada', 300);
Expand Down Expand Up @@ -76,6 +77,25 @@ select orders.id, orders.amount
from orders
where amount between 350 and 550;


# Like command (with wildcard)
select customers.id, customers.first_name, customers.last_name ,customers.country
from customers
where country like '%da';

select customers.id, customers.first_name, customers.last_name ,customers.country
from customers
where country like 'Ir%';

select customers.id, customers.first_name, customers.last_name ,customers.country
from customers
where country like 'Ir_n';

# Like command (without wildcard)
select customers.id, customers.first_name, customers.last_name ,customers.country
from customers
where country like 'Canada';

# See all of the customers
select customers.id, customers.country, customers.first_name, customers.last_name
from customers;
Expand All @@ -90,6 +110,3 @@ select customers.id, customers.country, customers.first_name, customers.last_nam
from customers
limit 2
offset 1;



0 comments on commit f48919a

Please sign in to comment.