Skip to content

Commit

Permalink
Update Lecture.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
omid-reza committed Feb 12, 2024
1 parent f4f3380 commit db32ed7
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions static/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 Down Expand Up @@ -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;



0 comments on commit db32ed7

Please sign in to comment.