Sunteți pe pagina 1din 12

ITM LAB

Assignment - 3

Question 1

Create a table ​Student, the Structure Table is:

Column name Data type Size


Reg_no varchar2 10
Name char 30
DOB date
Address varchar2 50

COMMAND

CREATE TABLE student

(Reg_no varchar2(10), Name char(30), DOB date, Address varchar2(50));

DESC student;

OUTPUT

Question 2
Create SALES table with attribute mentioned below:

Columns Type
Product_ID Integer (primary key)
Product Name Varchar
Quantity Integer
Price Integer

Shabeena 36180303917 MBA(2E)


ITM LAB

(a) Create table and assign constraints.


(b) Add new Column Variety as integer in the table.
(c) Find out the total for all products. (Total = Quantity * Price)
(d) Display all the details of the product whose quantity is more than 100.
(e) Display the details of the products for which the price is less than 10.

COMMANDS

(a) CREATE TABLE SALES

(Product_ID int NOT NULL, Product_Name varchar(20), Quantity int(5), Price


int(5), CONSTRAINT PK_SALES PRIMARY KEY (Product_ID));

INSERT INTO SALES VALUES ('101','ABC', '90', '15');

INSERT INTO SALES VALUES ('102','XYZ', '110', '7');

INSERT INTO SALES VALUES ('103','PQR', '70', '12');

INSERT INTO SALES VALUES ('104','MNO', '130', '8');

SELECT * FROM SALES;

OUTPUT

b) ALTER TABLE SALES ADD Variety varchar(10);

OUTPUT

Shabeena 36180303917 MBA(2E)


ITM LAB

c) ALTER TABLE SALES ADD Total int(20);

UPDATE SALES SET Total=Quantity*Price;

OUTPUT

d) SELECT Quantity FROM SALES

WHERE Quantity>100;

OUTPUT

e) SELECT Price FROM SALES

Shabeena 36180303917 MBA(2E)


ITM LAB

WHERE Price<10;

OUTPUT

Question 3
Create STUDENT table with attribute mention below: -

Table: STUDENT
Columns Student_ID Integer (primary key)
Student Name Varchar
Total Marks Integer
Maximum Marks Integer

(a) Create table and assign constraints.

(b) Set maximum marks as 500 for all the students.

(c) Find out the percentage of all the students.

(d) Display all the details of the students whose total marks are more than 300.

(e) Display the details of all the students with unique names.

COMMANDS

a) CREATE TABLE STUDENT

Shabeena 36180303917 MBA(2E)


ITM LAB

(Student_ID int NOT NULL, Student_Name varchar(10), Total_Marks int(5),


Maximum_Marks int(5), CONSTRAINT PK_STUDENT PRIMARY KEY
(Student_ID));

INSERT INTO STUDENT (Student_ID, Student_Name, Total_Marks)

VALUES ('1','Rohan','350');

INSERT INTO STUDENT (Student_ID, Student_Name, Total_Marks)

VALUES ('2','Sahil','270');

INSERT INTO STUDENT (Student_ID, Student_Name, Total_Marks)

VALUES ('3','Vanshika','430');

INSERT INTO STUDENT (Student_ID, Student_Name, Total_Marks)

VALUES('4','Atif','280');

SELECT * FROM STUDENT;

OUTPUT

b) UPDATE STUDENT

SET Maximum_Marks = '500';

OUTPUT

Shabeena 36180303917 MBA(2E)


ITM LAB

d) SELECT Student_ID, Student_Name, Total_Marks FROM STUDENT

WHERE Total_Marks>300;

OUTPUT

e) SELECT DISTINCT Student_Name

FROM STUDENT;

OUTPUT

Question 4

Sample table: salesman

salesman_id name city commission


----------- ----------- ---------- ------------------
5001 James Hoog New York 0.15
5002 Nail Knite Paris 0.13

Shabeena 36180303917 MBA(2E)


ITM LAB

5005 Pit Alex London 0.11


5006 Mc Lyon Paris 0.14
5003 Lauson Hen 0.12
5007 Paul Adam Rome 0.13

1. Write a query to filter those salesmen with all information who comes from any
of the cities Paris and Rome.
2. Write a SQL statement to find those salesmen with all information who come
from the city either Paris or Rome
3. Write a query to sort out those customers with all information whose ID value is
within any of 3007, 3008 and 3009.
4. Write a SQL statement to find those salesmen with all other information and
name started with other than any letter within 'A' and 'L'.
5. Write a SQL statement to display names and city of salesman, who belongs to the
city of Paris.

COMMANDS

1) CREATE TABLE salesman

(salesman_id int(5), name char(20), city char(10), commission float(5));

INSERT INTO salesman VALUES('5001', 'James Hoog', 'New York', '0.15');

INSERT INTO salesman VALUES('5002', 'Nail Knite', 'Paris', '0.13');

INSERT INTO salesman VALUES('5005', 'Pit Alex', 'London', '0.11');

INSERT INTO salesman VALUES('5006', 'Mc Lyon', 'Paris', '0.14');

INSERT INTO salesman VALUES('5003', 'Lauson', 'Hen', '0.12');

INSERT INTO salesman VALUES('5007', 'Paul Adam', 'Rome', '0.13');

SELECT * FROM salesman;

OUTPUT

Shabeena 36180303917 MBA(2E)


ITM LAB

2) SELECT * FROM salesman

WHERE city = 'Paris' OR city = 'Rome';

OUTPUT

3) SELECT * FROM salesman

WHERE salesman_id = '5007';

OUTPUT

4) SELECT * FROM salesman

WHERE name LIKE 'A%' OR name LIKE 'L%';

Shabeena 36180303917 MBA(2E)


ITM LAB

OUTPUT

5) SELECT * FROM salesman

WHERE city = 'Paris';

OUTPUT

Question 5
Sample table: item_mast

PRO_ID PRO_NAME PRO_PRICE PRO_COM

------- --- -------------------------- -------------------- ---------------

101 Mother Board 3200 15

102 Key Board 450 16

103 ZIP drive 250 14

104 Speaker 550 16

105 Monitor 5000 11

106 DVD drive 900 12

107 CD drive 800 12

108 Printer 2600 13

Shabeena 36180303917 MBA(2E)


ITM LAB

109 Refill cartridge 350 13

110 Mouse 250 12

1. Write a SQL query to find all the products with a price between Rs.200 and Rs.600
2. Write a SQL query to calculate the average price of all products of the
manufacturer whose code is l6.

COMMANDS

CREATE TABLE item_mast

(PRO_ID int(5), PRO_NAME char(20), PRO_PRICE int(5), PRO_COM int (5));

INSERT INTO item_mast VALUES ('101', 'Mother Board', '3200', '15');

INSERT INTO item_mast VALUES ('102', 'Key Board', '450', '16');

INSERT INTO item_mast VALUES ('103', 'ZIP drive', '250', '14');

INSERT INTO item_mast VALUES ('104', 'Speaker', '550', '16');

INSERT INTO item_mast VALUES ('105', 'Monitor', '5000', '11');

INSERT INTO item_mast VALUES ('106', 'DVD drive', '900', '12');

INSERT INTO item_mast VALUES ('107', 'CD drive', '800', '12');

INSERT INTO item_mast VALUES ('108', 'Printer', '2600', '13');

INSERT INTO item_mast VALUES ('109', 'Refill cartridge', '350', '13');

INSERT INTO item_mast VALUES ('110', 'Mouse', '250', '12');

SELECT * FROM item_mast;

Shabeena 36180303917 MBA(2E)


ITM LAB

OUTPUT

1) SELECT * FROM item_mast

WHERE PRO_PRICE>200 AND PRO_PRICE<600;

OUTPUT

2) SELECT PRO_ID, PRO_NAME, AVG(PRO_PRICE), PRO_COM

FROM item_mast

WHERE PRO_COM = '16';

Shabeena 36180303917 MBA(2E)


ITM LAB

OUTPUT

Shabeena 36180303917 MBA(2E)

S-ar putea să vă placă și