0% found this document useful (0 votes)
61 views7 pages

SQL HOT Questions 10 - 29

Important questions

Uploaded by

spandana r
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)
61 views7 pages

SQL HOT Questions 10 - 29

Important questions

Uploaded by

spandana r
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/ 7

1.

CREATE A TABLE STUDDENT USING COLUMN NAME AS PER FOLLOWING LIST


REGNO NAME ADDRESS FEES TOTAL MARKS
001 RAKESH MANGALORE 30000 455
002 ARYA BANGALORE 100000 580
003 SOUMYA MYSORE 50000 258
004 KIRAN BANGALORE 45000 415
005 SURESH MANGALORE 25000 196
Create table student (
regno number(4),
name varchar2(20),
address varchar2(30),
fees number(5) );

2. INSERT THE RECORDS


Insert into student values(001, ‘rakesh’,’mangalore’,25000);

3. ALTER THE COLUMN NAME TOTAL MARKS


Alter table student add(total number(3));

4. UPDATE THE COLUMN TOTAL MARKS USING CONDITION


Update student set total=455 where regno=001;

5. FIND LOWEST, HIGHEST AND AVERAGE MARKS OF STUDENT


Select max(total) from student;
Select min(total) from student;
Select avg(total) from student;

1. create table studentmarks containing following columns


regno varchar2(5)
name varchar2(20)
sub1 number(3)
sub2 number(3)
sub3 number(3)
create table studentmarks (
regno varchar2 (5),
name varchar2(20),
sub1 number(3),
sub2 number(3),
sub3 number(3) );

a)Add record into the table


insert into studentmarks values (‘a1001’, 'ananth', 67, 82, 86);

b)Display the description of the fields in the table


desc studentmarks;
c)Alter the table to add total number(3),max number(3), min number(3)
alter table studentmarks add (
total number(3),
max number(3),
min number(3) );
d)Calculate the total, minimum, maximum marks for each student
Calculating total
update studentmarks set total=sub1+sub2+sub3;

Calculating Maximum Marks:-


update studentmarks set max=greatest(sub1,sub2,sub3)

Calculating Minimum Marks:-


update studentmarks set min=least(sub1,sub2,sub3)

1. Write the SQL query for the following questions based on given employee table.

a. Develop the table with the above fields.


create table employee (
empid number (5),
name varchar2(20),
age number(3),
salary number(20) );
b. Display the structure of the table.
desc employee;

c. Find total number of employees.


Select count(*) from employee;

d. Find the sum of all employee’s salary.


Select sum(Salary) from student;

e. Display all employee records with age>=15.


Select * from employee where age>=15;

f. Alter the table by adding the field BONUS


alter table employee add(bonus number(50));

g. Update the bonus of all employees by giving bonus as 10% of SALARY.


Update employee set bonus=0.10*salary;
1. Using given SQL table write the appropriate SQL query.

a) To develop the table with above fields.


create table stud (
regno number (5),
name varchar2(20),
date date,
marks number(5) );
b) To find total number of students.
Select count(*) from stud;

c) To find highest marks.


Select max(marks) from stud;

d) To find lowest marks.


Select min(marks) from stud;

e) To display all students information whose marks is between 300 and 450
Select * from stud where marks between 300 and 450

h. Using given SQL table of electricity bill, write the appropriate SQL query.

a) To develop the table with above fields.


create table electr (
rrnumber varchar2 (10),
name varchar2(20),
billdate date,
units number(5),
amount number(10) );

b) To display the structure of a table.


Desc electr;

c) To find total number of customers.


Select count(*) from electr;

d) To find the total units consumed by all the customers.


Select sum(units) from electr;
e) To display all customers records in descending order
Select * from electr order by rrnumber desc

1. Using given SQL output, write the appropriate SQL query.


Reg no Name Total
1001 EEEE 475
12002 BBBB 574
1003 PPPP 510
1004 LLLL 596

a) To create following student table.


create table student (
regno varchar2 (10),
name varchar2(20),
total number(5) );
b) To find maximum of total marks.
Select max(total) from student;

c) To find minimum of total marks.


Select min(total) from student;

d) To count total number of students.


Select count(total) from student;

1. Create a table student using column name as per following list

REGNO NAME ADDRESS FEES TOTAL MARKS


001 RAKESH MANGALORE 30000 455
002 ARYA BANGALORE 100000 580
003 SOUMYA MYSORE 50000 258
004 KIRAN BANGALORE 45000 415
005 SURESH MANGALORE 25000 196

a) To create following student table


Create table student(
regno number(4),
name varchar2(20),
address varchar2(30),
fees number(5) );
b. Insert the records
Insert into student values(001, ‘rakesh’,’mangalore’,25000);

c. Alter the column name total marks


Alter table student add(total number(3));

d. Update the column total marks using condition


Update student set total=455 where regno=001;

e. Find lowest, highest and average marks of a student


Select max(total) from student;
Select min(total) from student;
Select avg(total) from student;

1. create table studentmarks containing following columns


regno varchar2(5)
name varchar2(20)
sub1 number(3)
sub2 number(3)
sub3 number(3)
a) Add 3 records into the table
b) Display the description of the fields in the table
c) Alter the table to add total number(3),max number(3), min number(3)
d) Calculate the total, minimum, maximum marks for each student

Answer:
create table studentmarks (
regno varchar2 (5),
name varchar2(20),
sub1 number(3),
sub2 number(3),
sub3 number(3) );

a)Add 3 records into the table


insert into studentmarks values (‘a1001’, 'ananth', 67, 82, 86);
insert into studentmarks values (‘a1002’, 'arjun', 32, 66, 78);
insert into studentmarks values (‘a1003’, 'karthik', 37, 65, 68);

b)Display the description of the fields in the table


desc studentmarks;

c)Alter the table to add total number(3),max number(3), min number(3)


alter table studentmarks add(
total number(3),
max number(3),
min number(3) );

d)Calculate the total, minimum, maximum marks for each student

Calculating Maximum Marks:-


update studentmarks set max=greatest(sub1,sub2,sub3) ;
Calculating Minimum Marks:-
update studentmarks set min=least(sub1,sub2,sub3);

1. Write the SQL query for the following questions based on given employee table.

a) Develop the table with the above fields.


b) Display the structure of the table.
c) Find total number of employees.
d) Find the sum of all employee’s salary.
e) Display all employee records with age>=15.
f) Alter the table by adding the field BONUS
g) Update the bonus of all employees by giving bonus as 10% of SALARY.

2. Using given SQL table write the appropriate SQL query.

f) To develop the table with above fields.


g) To find total number of students.
h) To find highest marks.
i) To find lowest marks.
j) To display all students information whose marks is between 300 and 450

3. Using given SQL table of electricity bill, write the appropriate SQL query.

e) To develop the table with above fields.


f) To display the structure of a table.
g) To find total number of customers.
h) To find the total units consumed by all the customers.
i) To display all customers records in descending order

You might also like