0% found this document useful (0 votes)
8 views

Dbms Lab Problem Solution

Uploaded by

Riki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Dbms Lab Problem Solution

Uploaded by

Riki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

(Q) Create table and insert data according to the query.

(a)create customer table

create table customer(customer_id number not null primary key,

customer_name varchar2(255),

gender varchar2(255));

desc customer

(b)create item table

create table item(item_id number not null primary key,

item_name varchar2(255),

item_price number,

sold_date date,

sold_quantity number,

item_category varchar2(255),

item_company varchar2(255));

desc item
(c)create seller table

create table seller(seller_id number not null primary key,

seller_name varchar2(255),

item_id number references item(item_id),

sell_quantity number);

desc seller

(d)create orders table

create table orders(order_id number,

customer_id number references customer(customer_id),

item_id number references item(item_id),

seller_id number references seller(seller_id),

item_replaced_status varchar2(255),

order_quantity number,

order_date date,

payment_mode varchar2(255),

bank_name varchar2(255));

desc orders
(e)Insert data into customer table

insert into customer values(1,'saklin','male');

insert into customer values(2,'souvik','male');

insert into customer values(3,'pinki','female');

insert into customer values(4,'sangita','female');

insert into customer values(5,'sohel','male');

insert into customer values(6,'sayemah','female');

insert into customer values(7,'kritty','male');

insert into customer values(8,'akash','male');

insert into customer values(9,'farhana','female');

insert into customer values(10,'sahanaj','female');

select *from customer

(f)Insert data into item table

insert into item values(1,'redmi 9 pro smartphone',16500,to_date('22-10-2023','DD-MM-


YYYY'),500,'smartphone','redmi');

insert into item values(2,'samsung j7 smartphone',16000,to_date('23-10-2023','DD-MM-


YYYY'),400,'smartphone','samsung');

insert into item values(3,'ear ring',2500,to_date('22-10-2023','DD-MM-YYYY'),5000,'ornaments','pc


chandra');
insert into item values(4,'bangles',4000,to_date('27-10-2023','DD-MM-YYYY'),2500,'ornaments','pc
chandra');

insert into item values(5,'shirt',1000,to_date('22-11-2023','DD-MM-YYYY'),700,'men items','turtle');

insert into item values(6,'pant',1200,to_date('22-12-2023','DD-MM-YYYY'),800,'men items','turtle');

insert into item values(7,'samsung j2 smartphone',7000,to_date('15-11-2023','DD-MM-


YYYY'),200,'smartphone','samsung');

insert into item values(8,'samsung gt smartphone',4500,to_date('19-11-2023','DD-MM-


YYYY'),100,'smartphone','samsung');

insert into item values(9,'redmi note10 smartphone',18500,to_date('22-12-2023','DD-MM-


YYYY'),600,'smartphone','redmi');

insert into item values(10,'ear ring',4500,to_date('29-10-2023','DD-MM-


YYYY'),2000,'ornaments','tanishq');

select *from item

(g)Insert data into seller table

insert into seller values(1,'infotech',1,100);

insert into seller values(2,'mart',3,1000);

insert into seller values(3,'infotech',2,200);

insert into seller values(4,'infotech',9,300);

insert into seller values(5,'techno',7,100);

insert into seller values(6,'mart',4,1500);

insert into seller values(7,'jack',5,500);


insert into seller values(8,'jack',6,400);

insert into seller values(9,'techno',8,500);

insert into seller values(10,'anjali',10,2000);

select *from seller

(h)Insert data into orders table

insert into orders values(1,1,1,1,'no',5,to_date('01-08-2023','DD-MM-YYYY'),'upi','sbi');

insert into orders values(1,1,3,2,'yes',2,to_date('04-08-2023','DD-MM-YYYY'),'upi','sbi');

insert into orders values(2,2,2,3,'no',1,to_date('16-08-2023','DD-MM-YYYY'),'netbanking','sbi');

insert into orders values(2,2,6,8,'no',2,to_date('10-08-2023','DD-MM-YYYY'),'netbanking','hdfc');

insert into orders values(3,3,9,4,'no',1,to_date('25-08-2023','DD-MM-YYYY'),'credit card','axis');

insert into orders values(3,3,4,6,'yes',1,to_date('25-09-2023','DD-MM-YYYY'),'credit card','axis');

insert into orders values(4,4,8,9,'no',1,to_date('25-10-2023','DD-MM-YYYY'),'debit card','pnb');

insert into orders values(4,4,10,10,'no',3,to_date('29-11-2023','DD-MM-YYYY'),'debit card','pnb');

insert into orders values(5,5,7,5,'no',1,to_date('28-10-2023','DD-MM-YYYY'),'offline','');

insert into orders values(6,6,5,7,'no',10,to_date('25-10-2023','DD-MM-YYYY'),'debit card','sbi');

insert into orders values(2,2,9,3,'no',5,to_date('16-10-2023','DD-MM-YYYY'),'upi','sbi');


select *from orders

Q1. List the customers who have ordered Redmi 9 pro smartphone.

=> SELECT c.customer_id,c.customer_name from customer c

JOIN orders o ON o.customer_id=c.customer_id

JOIN item i ON o.item_id = i.item_id

WHERE i.item_name='redmi 9 pro smartphone';

Q2. List customers who have ordered the items above 10000 and dispaly the item too

=>SELECT c.customer_id,c.customer_name,i.item_name from customer c

JOIN orders o ON o.customer_id=c.customer_id

JOIN item i ON o.item_id = i.item_id

WHERE i.item_price>10000;
Q3. List the items which have been sold out more in number from October to December.

=> SELECT item_id,item_name,sold_quantity

FROM item WHERE sold_date BETWEEN to_date('01-10-2023','DD-MM-YYYY') AND to_date('30-12-


2023','DD-MM-YYYY');

Q4. List the items which have been replaced by the customers.

=> SELECT i.item_id,i.item_name from item i

JOIN orders o ON o.item_id=i.item_id

WHERE item_replaced_status='yes';

Q5. List the items which are from 2000 to 3000 rs.

=> SELECT item_id,item_name

FROM item WHERE item_price BETWEEN 2000 AND 3000;


Q6. List the items which have more than 3 categories.

=> SELECT item_name FROM item

WHERE item_category IN(select item_category from item group by item_category having


count(item_category)>3);

Q7. List the customers who have ordered the item through netbanking.

=> SELECT c.customer_id,c.customer_name,i.item_name FROM customer c

JOIN orders o ON o.customer_id=c.customer_id

JOIN item i ON o.item_id=i.item_id

WHERE o.payment_mode='netbanking';

Q8. List the sellers who have sold the mobile phone more than 1000 pieces.

=> SELECT seller_id,seller_name FROM seller

WHERE sell_quantity>1000;
Q9. Count the female and male customers who have purchased ornaments.

=> SELECT count(c.customer_name) FROM customer c

JOIN orders o ON o.customer_id=c.customer_id

JOIN item i ON o.item_id=i.item_id

WHERE item_category='ornaments' AND (gender='female' OR gender='male');

Q10. Count the female customers who have purchased the men items.

=> SELECT count(c.customer_name) FROM customer c

JOIN orders o ON o.customer_id=c.customer_id

JOIN item i ON o.item_id=i.item_id

WHERE item_category='men items' AND gender='female';

Q11. List the Item which have been sold in second largest number.

=> SELECT item_name from item

WHERE sold_quantity=(SELECT max(sold_quantity) from item

WHERE sold_quantity!=(SELECT max(sold_quantity) from item));


Q12. Count the customers who have purchased mobile phone from different companies.

=> SELECT COUNT(c.customer_name),customer_name

FROM customer c

JOIN orders o ON o.customer_id = c.customer_id

JOIN item i ON o.item_id = i.item_id

WHERE item_category = 'smartphone'

GROUP BY c.customer_name

HAVING COUNT(DISTINCT item_company) > 1;

Q13. Find the customers who have purchased maximum number of mobile phones for a particular
company.

=> SELECT i.item_company,c.customer_name,o.order_quantity

FROM customer c

JOIN orders o ON c.customer_id = o.customer_id

JOIN item i ON o.item_id = i.item_id

WHERE i.item_category = 'smartphone' AND i.item_company = 'redmi'

AND o.order_quantity = (

SELECT MAX(order_quantity)

FROM orders o1

JOIN item i1 ON o1.item_id = i1.item_id

WHERE i1.item_category = 'smartphone' AND i1.item_company = 'redmi'

GROUP BY i.item_company,c.customer_name,o.order_quantity;
Q14. Find the item which have been sold maximum in number.

=> SELECT item_name from item

WHERE sold_quantity=(SELECT max(sold_quantity) from item);

Q15. Find the bank name which has maximum selling point through any transaction.

=> SELECT bank_name from orders where order_quantity=(select max(order_quantity) from orders);

Q16. List the customers who have used both the ttansaction mode as UPI and Netbanking for SBI
bank.

=> SELECT distinct c.customer_name

FROM customer c

JOIN orders o1 ON o1.customer_id = c.customer_id

JOIN orders o2 ON o2.customer_id = c.customer_id

WHERE o1.payment_mode = 'upi' AND o2.payment_mode = 'netbanking';

You might also like