Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions 1907011_Online_Mobile_Shop_Management_System/DDL.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
create table member(
mem_id number(5) check(length(mem_id)=5) not null primary key,
username varchar(50) not null,
password varchar(20) check(length(password)>=6) not null,
email varchar(50) unique not null,
address varchar(50),
phone varchar(11) check(length(phone)=11) not null
);


create table mobile(
pro_id number(5) check(length(pro_id)=5) not null primary key,
pro_name varchar(50) not null,
pro_model number(10) not null,
pro_desc varchar(450),
amount number(30) not null,
color varchar(20));

create table rating(
rating_id number(4) check(length(rating_id)=4) not null primary key,
mem_id number(5) check(length(mem_id)=5) not null,
pro_id number(5) check(length(pro_id)=5) not null,
value number(2,1) not null,
foreign key(mem_id) references member(mem_id) on delete cascade,
foreign key(pro_id) references mobile(pro_id) on delete cascade);


create table cart(
cart_id number(4) check(length(cart_id)=4) not null primary key,
mem_id number(5) check(length(mem_id)=5) not null,
pro_id number(5) check(length(pro_id)=5) not null,
quantity number not null,
foreign key(mem_id) references member(mem_id) on delete cascade,
foreign key(pro_id) references mobile(pro_id) on delete cascade);


create table transaction(
transaction_id number(4) check(length(transaction_id)=4) not null primary key,
mem_id number(5) check(length(mem_id)=5) not null,
cart_id number(4) check(length(cart_id)=4) not null,
payment_amount number(20) not null,
payment_date DATE not null,
foreign key(mem_id) references member(mem_id) on delete cascade,
foreign key(cart_id) references cart(cart_id) on delete cascade);


--1.add column
alter table member add name char(20);
--2.modify column
alter table member modify name varchar(50);
--3.rename column
alter table member rename column name to fullname;
--4.delete column
alter table member drop column fullname;


258 changes: 258 additions & 0 deletions 1907011_Online_Mobile_Shop_Management_System/DML.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
insert into member (mem_id, username, password, email, address, phone) values (11111, 'Jesi', 'password1', 'jesi@gmail.com', 'Khulna', '01790078350');
insert into member (mem_id, username, password, email, address, phone) values (22222, 'Luna', 'password2', 'luna@email.com', 'Bornali,Rajshahi', '01790078351');
insert into member (mem_id, username, password, email, address, phone) values (33333, 'Jezz', 'password3', 'jezz@email.com', 'Bongura,Comilla', '01790078352');
insert into member (mem_id, username, password, email, address, phone) values (44444, 'Nova', 'password4', 'nova@email.com', 'Mirpur-14,Dhaka', '01790078353');
insert into member (mem_id, username, password, email, address, phone) values (55555, 'Ruby', 'password5', 'ruby@email.com', 'Natore', '01790078354');
insert into member (mem_id, username, password, email, address, phone) values (66666, 'Ivy', 'password6', 'ivy@email.com', 'Bogura', '01790078355');
insert into member (mem_id, username, password, email, address, phone) values (77777, 'Finn', 'password7', 'finn@email.com', 'Sylhet', '01790078356');
insert into member (mem_id, username, password, email, address, phone) values (88888, 'Max', 'password8', 'max@email.com', 'Pabna', '01790078357');
insert into member (mem_id, username, password, email, address, phone) values (99999, 'Milo', 'password9', 'milo@email.com', 'Luxmipur,Rajshahi', '01790078358');
insert into member (mem_id, username, password, email, address, phone) values (10101, 'Semon', 'password10', 'semon@email.com', 'Shaheb Bajar,Rajshahi', '01790078359');



insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10001, 'Xiaomi Redmi Note 12', 111,'1.6.67-inch Super AMOLED display
2.Snapdragon 4 Gen 1 chipset,4GB RAM
3.85.0% screen-to-body ratio
4.Corning Gorilla Glass 3
5.48MP primary, 8MP ultrawide, and a 2MP additional lens
6.5000mAh battery with 33W fast charging' , 20000, 'Green');

insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10002, 'Oppo F19 pro+', 222, '1.6.43-inch Super AMOLED display
2.800U Octa Core processor,8GB RAM,128GB storage
3.84.9% screen-to-body ratio
4.Corning Gorilla Glass 5
5.48MP primary, 2MP macro, and a 2MP depth sensor
6.4310mAh battery with 50W fast charging', 18000, 'Gray');
insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10003, 'Redmi Note 10 Pro', 333, '1.AMOLED display
2.Snapdragon 4 Gen 1 chipset,4GB RAM
3.85.0% screen-to-body ratio
4.Corning Gorilla Glass 3
5.48MP primary, 8MP ultrawide, and a 2MP additional lens
6.5020mAh battery with 33W fast charging', 20000, 'Ocean Blue');
insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10004, 'iQOO Z7 5G', 444, '1.6.38-inch AMOLED display
2.MediaTek Dimensity 920 chipset,6GB RAM,128GB ROM
3.84.14% screen-to-body ratio
4.Corning Gorilla Glass 3
5. 64MP primary and a 2MP additional lens
6.5000mAh battery with 33W fast charging', 18999, 'Blue');
insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10005, 'Realme 10', 555, '1.6.4-inch Super AMOLED display
2. MediaTek Helio G99 SoC,4GB RAM
3.84.4% screen-to-body ratio
4.Corning Gorilla Glass 3
5.50MP primary and a 2MP additional lens.
6.5000mAh battery with 33W fast charging', 14450, 'Gray');
insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10006, 'Realme 8', 666, '1.AMOLED display
2.4GB RAM,128GB ROM
3.85.0% screen-to-body ratio
4.Corning Gorilla Glass 3
5.48MP primary, 8MP ultrawide, and a 2MP additional lens
6.5000mAh battery with 30W fast charging', 20000, 'Green');
insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10007, 'Xiaomi Redmi Note 11 SE', 777, '1.6.43-inch Super AMOLED display
2.MediaTek Helio G95 chipset with 6GB RAM
3.83.53% screen-to-body ratio
4.Corning Gorilla Glass 3
5.64MP primary, 8MP ultrawide, and a 2MP additional lens
6.5000mAh battery with 33W fast charging', 11999, 'Green');
insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10008, 'Samsung Galaxy M32', 888, '1.6.4-inch Super AMOLED display
2.MediaTek Helio G80 chipset with 4GB RAM
3.98.9% screen-to-body ratio
4.Corning Gorilla Glass 3
5.64MP primary, 8MP ultrawide, and a 2MP additional lens
6.6000mAh battery with 33W fast charging', 13399, 'Green');
insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10009, 'Poco X5', 999, '1.6.67-inch Super AMOLED display
2.Snapdragon 695 chipset,6GB RAM
3.85.02% screen-to-body ratio
4.Corning Gorilla Glass 3
5.48MP primary, 8MP ultrawide, and a 2MP additional lens
6.5000mAh battery with 33W fast charging', 18999, 'Green');
insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10010, 'Motorola Moto G71', 101, '1.6.4-inch AMOLED display
2.Snapdragon 4 Gen 1 chipset,4GB RAM
3.85.0% screen-to-body ratio
4.Corning Gorilla Glass 3
5.48MP primary, 8MP ultrawide, and a 2MP additional lens
6.5000mAh battery with 33W fast charging', 19000, 'Arctic Blue');

insert into rating (rating_id, mem_id, pro_id, value) values (1111, 11111, 10001, 9.9);
insert into rating (rating_id, mem_id, pro_id, value) values (2222, 11111, 10002, 7.9);
insert into rating (rating_id, mem_id, pro_id, value) values (3333, 22222, 10001, 6.9);
insert into rating (rating_id, mem_id, pro_id, value) values (4444, 33333, 10001, 9.5);
insert into rating (rating_id, mem_id, pro_id, value) values (5555, 55555, 10001, 9.7);
insert into rating (rating_id, mem_id, pro_id, value) values (6666, 11111, 10003, 8.9);
insert into rating (rating_id, mem_id, pro_id, value) values (7777, 11111, 10004, 7.9);
insert into rating (rating_id, mem_id, pro_id, value) values (8888, 88888, 10008, 5.9);
insert into rating (rating_id, mem_id, pro_id, value) values (9999, 33333, 10006, 8.9);
insert into rating (rating_id, mem_id, pro_id, value) values (1010, 77777, 10006, 9.9);

insert into cart (cart_id, mem_id, pro_id, quantity) values (1001, 11111, 10001, 2);
insert into cart (cart_id, mem_id, pro_id, quantity) values (1002, 22222, 10005, 1);
insert into cart (cart_id, mem_id, pro_id, quantity) values (1003, 77777, 10001, 2);
insert into cart (cart_id, mem_id, pro_id, quantity) values (1004, 33333, 10002, 3);
insert into cart (cart_id, mem_id, pro_id, quantity) values (1005, 11111, 10006, 1);
insert into cart (cart_id, mem_id, pro_id, quantity) values (1006, 11111, 10007, 1);
insert into cart (cart_id, mem_id, pro_id, quantity) values (1007, 88888, 10009, 1);
insert into cart (cart_id, mem_id, pro_id, quantity) values (1008, 88888, 10002, 1);
insert into cart (cart_id, mem_id, pro_id, quantity) values (1009, 44444, 10001, 2);
insert into cart (cart_id, mem_id, pro_id, quantity) values (1010, 33333, 10003, 1);


insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1011, 11111, 1001, 40000, date '2023-05-01');
insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1022, 22222, 1002, 14450, date '2023-05-04');
insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1033, 77777, 1003, 40000, date '2023-04-02');
insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1044, 33333, 1004, 54000, date '2023-05-09');
insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1055, 11111, 1005, 20000, date '2023-04-08');
insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1066, 11111, 1006, 11999, date '2023-05-09');
insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1077, 88888, 1007, 18999, date '2023-05-08');
insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1088, 88888, 1008, 18000, date '2023-05-04');
insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1099, 44444, 1009, 40000, date '2023-05-20');
insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1012, 33333, 1010, 20000, date '2023-05-06');





--QUERY

---Displaying data using select command--
--1
select * from member;
--2
select * from mobile;
--3
select * from rating;
--4
select * from cart;
--5
select * from transaction;
--6
select * from rating where mem_id=11111;
--7
select * from rating where value=9.9;




--Nested subquery
--8
select username from member where mem_id=(select mem_id from rating where rating_id=1111);
--9
select pro_name from mobile where pro_id=(select pro_id from cart where cart_id=(select cart_id from transaction where payment_date=date '2023-05-01'));

--Updating data
--10
update member set username='Jesu' where mem_id=11111;
select * from member;

--Deleting a row
--11
insert into member (mem_id, username, password, email, address, phone) values (10111, 'Semn', 'password11', 'semn@email.com', 'Shaheb Bajar,Rajshahi', '01790078309');
delete from member where mem_id=10111;



--Select Distinct/all
--12
select distinct mem_id from transaction;
--13
select all mem_id from transaction;
--14
select distinct(amount),pro_name from mobile;

--Select with arithmetic operation
--15
select pro_model,amount/10 as dis_amount from mobile;


--The where clause
--16
select pro_id from rating where value>7;
--17
select member.username,mobile.pro_name from member,mobile where amount>19000;

--Rename Operation
--18
select m.username,mob.pro_name from member m,mobile mob where amount>19000;

--String Operation
--19
select username from member where username like 'J%';
--20
select username,email from member where username like '___' or username like '____';


--Order by Clause--
--21
select username,email from member order by email;

--Where clause predicates
--22
select pro_name,amount from mobile where amount between 15000 and 19000;

--Set operations(union,intersection)
--23
select username from member where username like 'J___' union select username from member where username like '___';
--24
select username from member where username like 'J___' intersect select username from member where username like '___';


--25-Agregate Functions
select count(cart_id) as no_of_cart from transaction;
--26
select avg(payment_amount) from transaction group by cart_id;
--27
select sum(amount) from mobile;
--28
select max(amount) from mobile;
--29
select min(amount) from mobile;


--Group by and Having
--30
select pro_id,avg(quantity) from cart group by pro_id having avg(quantity)>=2;

--Set Membership
--31
select mem_id from cart where pro_id = 10001 and mem_id in (select mem_id from cart where pro_id=10007);
--32
select mem_id from cart where pro_id = 10001 and mem_id not in (select mem_id from cart where pro_id=10002);


--Some/All/Exists
--33
select * from cart where quantity> some(select quantity from cart where quantity>=2);
--34
select * from cart where quantity> all(select quantity from cart where quantity>=1);
--35
select * from rating where value>=8 and exists(select * from member where username like 'J%');

--With clause
--36
with max_amount(val) as (select max(amount) from mobile)
select pro_name,amount from mobile,max_amount where mobile.amount=max_amount.val;

--Join--
--37
select * from member natural join rating where mem_id=11111;
--38
select username,value from member join rating using(mem_id);
--39
select username,value from member join rating on member.mem_id=rating.mem_id;
--40
select username,value from member left outer join rating using(mem_id);
--41
select username,value from member right outer join rating using(mem_id);
--42
select username,value from member full outer join rating using(mem_id);


--View--
--43
create view user_details as select username,email from member;
select * from user_details;
--44
create view products as select pro_name from mobile where pro_id=(select pro_id from cart where quantity>2);
select * from products;
--45
create view user_details2 as select * from user_details where username like 'J___';
select * from user_details2;
Loading