SlideShare a Scribd company logo
1 of 8
ASSISNMENT:1
TABLE CREATION:

1. create table course(course_no char(4) primary key,course_name
varchar(20));

2. create table course_fee(course_no char(4) unique,full_part char(1),fees
number(10),foreign key(course_no) references course);

3. create table student(prospectus_no number(10) primary key,name
varchar(20),
address varchar(30),phone_no number(11),D_O_B date,total_amt
number(10,2),amt_paid number(10,2),installment char(1));

4. create table installment(prospectus_no number(10)
unique,installment_amt number(10,2),due_dt date unique,paid
char(1),foreign key(prospectus_no) references
 student on delete cascade);

5. create table course_taken(prospectus_no number(10),course_no
char(4),start_dt date,full_part char(1),time_slot char(2),performance
varchar(20),foreign key(prospectus_no) references student,foreign
key(course_no) references course);


INSERTING VALUES:


1. insert into course values('c1','LINUX');

insert into course values('c2','UNIX');

insert into course values('c3','ORACLE');

insert into course values('c4','JAVA');


2. insert into course_fee values('c1','F',10000);
insert into course_fee values('c2','F',8000);

insert into course_fee values('c3','P',12000);

insert into course_fee values('c4','P',14000);


3. insert into student values(12345,'student1','address1',123456,'01-
JANUARY-1990',20000,10000,'I');

insert into student values(22345,'student2','address2',223456,'02-
FEBRUARY-1990',20000,20000,'F');

insert into student values(32345,'student3','address3',323456,'03-
MARCH-1990',10000,8000,'I');

insert into student values(42345,'student4','address4',423456,'04-
APRIL-1990',12000,12000,'F');

insert into student values(52345,'student5','address5',523456,'05-MAY-1990'
,12000,10000,'I');


4. insert into installment values(12345,5000,'22-AUGUST-2010','U');

insert into installment values(22345,20000,'23-AUGUST-2010','P');

insert into installment values(32345,2000,'24-AUGUST-2010','U');

insert into installment values(42345,12000,'24-SEPTEMBER-2010','P');

insert into installment values(52345,1000,'29-SEPTEMBER-2010','U');


5. insert into course_taken values(12345,'c1','29-
SEPTEMBER-2010','F','AN','GOOD');

insert into course_taken values(22345,'c1','30-
SEPTEMBER-2010','F','FN','GOOD');
insert into course_taken values(32345,'c2','30-
SEPTEMBER-2010','F','FN','GOOD');

insert into course_taken values(42345,'c3','28-
SEPTEMBER-2010','P','AN','GOOD');

insert into course_taken values(52345,'c4','30-
SEPTEMBER-2010','P','AN','GOOD');


QUERIES:

Q1. Retrieve name and course no. of all students.

select student.name,course_taken.course_no
 from student,course_taken
 where student.prospectus_no=course_taken.prospectus_no;


NAME                   COUR
--------------------   ----
student1                c1
student2                c1
student3                c2
student4                c3
student5                c4


Q2. List the names of students who have paid the full amount at the time of
admission

select name
 from student
 where total_amt=amt_paid;

NAME
--------------------
student2
student4
Q3. Find the names of students starting with A.

select *
from student
where name like 'A%';

no rows selected


Q4. Print the names of students whose total amount is not equal to amount
due.

select student.name
from student
where amt_paid
not in(select amt_paid from student where total_amt=amt_paid);

NAME
--------------------
student1
student3
student5




Q5. Count the number of students who have joined in current year, current
month.

select count(*)
 from course_taken
 where start_dt like '___SEP_10';

 COUNT(*)
 ----------
     5
Q6. Determine the maximum and minimum course fees.

select max(fees),min(fees)
from course_fee;

 MAX(FEES) MIN(FEES)
----------- ---------
    14000   8000


Q7. Increase the fee of Oracle by 50%.

update course_fee
set fees=1.5*fees
where fees in(select course_fee.fees from course_fee,course
where course.course_no=course_fee.course_no and
course.course_name='ORACLE');


Q8. Print the details of courses whose fees are between 5000 and 10000.

select
course.course_no,course.course_name,course_fee.fees,course_fee.full_part
 from course,course_fee
 where course.course_no=course_fee.course_no and (course_fee.fees>5000
and course_fee.fees<10000);

COUR           COURSE_NAME                FEES       F
----           --------------------      ---------- -
c2              UNIX                      8000      F


Q9. Display the admission date in DD-MONTH-YY format

select TO_CHAR(start_dt,'dd-month-yyyy')
as start_dt
from course_taken;

START_DT
-----------------
29-september-2010
30-september-2010
30-september-2010
28-september-2010
30-september-2010


Q10. Find out in which course maximum number of students have taken
admission.

select course.course_name
 from course,course_taken
 where course.course_no=course_taken.course_no
 group by course.course_name
 having count(course_taken.prospectus_no)>=all
 (select count(prospectus_no)
 from course_taken
 group by course_no);

COURSE_NAME
--------------------
LINUX


Q11. Change the course_name from Unix to Unix OS.

update course
set course_name='UNIX OS'
where course_name='UNIX';


Q12. Get the sum of amount to be collected from students in this month.

select sum(student.total_amt-student.amt_paid)
from student,installment
where student.prospectus_no=installment.prospectus_no
and installment.due_dt like '___SEP_10';

SUM(STUDENT.TOTAL_AMT-STUDENT.AMT_PAID)
---------------------------------------
2000

.
 Q13. Find out in which course maximum number of students have taken
admission in the current month.

select course.course_name
from course,course_taken
where course.course_no=course_taken.course_no and start_dt like
'___SEP_10'
group by course.course_name
having count(course_taken.prospectus_no)>=all
(select count(prospectus_no)
 from course_taken
 group by course_no);


COURSE_NAME
--------------------
LINUX


Q14. Select the students who have not yet paid full amount of fees.

select name
from student
where total_amt>amt_paid;

NAME
--------------------
student1
student3
student5
ASSIGNMENT 1

More Related Content

What's hot (20)

Arrays C#
Arrays C#Arrays C#
Arrays C#
 
Java Queue.pptx
Java Queue.pptxJava Queue.pptx
Java Queue.pptx
 
Life cycle-of-a-thread
Life cycle-of-a-threadLife cycle-of-a-thread
Life cycle-of-a-thread
 
Function
FunctionFunction
Function
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
 
DBMS Practical File
DBMS Practical FileDBMS Practical File
DBMS Practical File
 
Dbms
DbmsDbms
Dbms
 
Variadic functions
Variadic functionsVariadic functions
Variadic functions
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
Sql
SqlSql
Sql
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Java arrays
Java arraysJava arrays
Java arrays
 
User defined Function in SQL
User defined Function in SQLUser defined Function in SQL
User defined Function in SQL
 
I/O Streams
I/O StreamsI/O Streams
I/O Streams
 
Storage Class in C Progrmming
Storage Class in C Progrmming Storage Class in C Progrmming
Storage Class in C Progrmming
 
Chapter 4 strings
Chapter 4 stringsChapter 4 strings
Chapter 4 strings
 
POINTERS IN C
POINTERS IN CPOINTERS IN C
POINTERS IN C
 
Arrays In C Language
Arrays In C LanguageArrays In C Language
Arrays In C Language
 
Array in C
Array in CArray in C
Array in C
 

Viewers also liked

Manufacturing Process of Plastic Bags
Manufacturing Process of Plastic BagsManufacturing Process of Plastic Bags
Manufacturing Process of Plastic BagsKingsun Machinery
 
FFEA 2016 -10 Website Mistakes Even Great Marketers Can Make
FFEA 2016 -10 Website Mistakes Even Great Marketers Can MakeFFEA 2016 -10 Website Mistakes Even Great Marketers Can Make
FFEA 2016 -10 Website Mistakes Even Great Marketers Can MakeSaffire
 
5 Steps To A Smart Compensation Plan
5 Steps To A Smart Compensation Plan5 Steps To A Smart Compensation Plan
5 Steps To A Smart Compensation PlanBambooHR
 
The Presentation Come-Back Kid
The Presentation Come-Back KidThe Presentation Come-Back Kid
The Presentation Come-Back KidEthos3
 
10 Tips for WeChat
10 Tips for WeChat10 Tips for WeChat
10 Tips for WeChatChris Baker
 
Benefits of drinking water
Benefits of drinking waterBenefits of drinking water
Benefits of drinking waterEason Chan
 

Viewers also liked (7)

Manufacturing Process of Plastic Bags
Manufacturing Process of Plastic BagsManufacturing Process of Plastic Bags
Manufacturing Process of Plastic Bags
 
FFEA 2016 -10 Website Mistakes Even Great Marketers Can Make
FFEA 2016 -10 Website Mistakes Even Great Marketers Can MakeFFEA 2016 -10 Website Mistakes Even Great Marketers Can Make
FFEA 2016 -10 Website Mistakes Even Great Marketers Can Make
 
5 Steps To A Smart Compensation Plan
5 Steps To A Smart Compensation Plan5 Steps To A Smart Compensation Plan
5 Steps To A Smart Compensation Plan
 
Stay Up To Date on the Latest Happenings in the Boardroom: Recommended Summer...
Stay Up To Date on the Latest Happenings in the Boardroom: Recommended Summer...Stay Up To Date on the Latest Happenings in the Boardroom: Recommended Summer...
Stay Up To Date on the Latest Happenings in the Boardroom: Recommended Summer...
 
The Presentation Come-Back Kid
The Presentation Come-Back KidThe Presentation Come-Back Kid
The Presentation Come-Back Kid
 
10 Tips for WeChat
10 Tips for WeChat10 Tips for WeChat
10 Tips for WeChat
 
Benefits of drinking water
Benefits of drinking waterBenefits of drinking water
Benefits of drinking water
 

Similar to SQL Assignment on Table Creation, Data Insertion and Queries

SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankMd Mudassir
 
[APJ] Common Table Expressions (CTEs) in SQL
[APJ] Common Table Expressions (CTEs) in SQL[APJ] Common Table Expressions (CTEs) in SQL
[APJ] Common Table Expressions (CTEs) in SQLEDB
 
Programming the SQL Way with Common Table Expressions
Programming the SQL Way with Common Table ExpressionsProgramming the SQL Way with Common Table Expressions
Programming the SQL Way with Common Table ExpressionsEDB
 
sql code for this question below Portland Airports Ltd would like a.pdf
sql code  for this question below  Portland Airports Ltd would like a.pdfsql code  for this question below  Portland Airports Ltd would like a.pdf
sql code for this question below Portland Airports Ltd would like a.pdfdawarhosy
 

Similar to SQL Assignment on Table Creation, Data Insertion and Queries (9)

SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question Bank
 
Dbms record
Dbms recordDbms record
Dbms record
 
BScPLSQL.pdf
BScPLSQL.pdfBScPLSQL.pdf
BScPLSQL.pdf
 
[APJ] Common Table Expressions (CTEs) in SQL
[APJ] Common Table Expressions (CTEs) in SQL[APJ] Common Table Expressions (CTEs) in SQL
[APJ] Common Table Expressions (CTEs) in SQL
 
My Sql
My Sql My Sql
My Sql
 
Programming the SQL Way with Common Table Expressions
Programming the SQL Way with Common Table ExpressionsProgramming the SQL Way with Common Table Expressions
Programming the SQL Way with Common Table Expressions
 
Quiz using C++
Quiz using C++Quiz using C++
Quiz using C++
 
sql code for this question below Portland Airports Ltd would like a.pdf
sql code  for this question below  Portland Airports Ltd would like a.pdfsql code  for this question below  Portland Airports Ltd would like a.pdf
sql code for this question below Portland Airports Ltd would like a.pdf
 
DECLARE example
DECLARE exampleDECLARE example
DECLARE example
 

SQL Assignment on Table Creation, Data Insertion and Queries

  • 1. ASSISNMENT:1 TABLE CREATION: 1. create table course(course_no char(4) primary key,course_name varchar(20)); 2. create table course_fee(course_no char(4) unique,full_part char(1),fees number(10),foreign key(course_no) references course); 3. create table student(prospectus_no number(10) primary key,name varchar(20), address varchar(30),phone_no number(11),D_O_B date,total_amt number(10,2),amt_paid number(10,2),installment char(1)); 4. create table installment(prospectus_no number(10) unique,installment_amt number(10,2),due_dt date unique,paid char(1),foreign key(prospectus_no) references student on delete cascade); 5. create table course_taken(prospectus_no number(10),course_no char(4),start_dt date,full_part char(1),time_slot char(2),performance varchar(20),foreign key(prospectus_no) references student,foreign key(course_no) references course); INSERTING VALUES: 1. insert into course values('c1','LINUX'); insert into course values('c2','UNIX'); insert into course values('c3','ORACLE'); insert into course values('c4','JAVA'); 2. insert into course_fee values('c1','F',10000);
  • 2. insert into course_fee values('c2','F',8000); insert into course_fee values('c3','P',12000); insert into course_fee values('c4','P',14000); 3. insert into student values(12345,'student1','address1',123456,'01- JANUARY-1990',20000,10000,'I'); insert into student values(22345,'student2','address2',223456,'02- FEBRUARY-1990',20000,20000,'F'); insert into student values(32345,'student3','address3',323456,'03- MARCH-1990',10000,8000,'I'); insert into student values(42345,'student4','address4',423456,'04- APRIL-1990',12000,12000,'F'); insert into student values(52345,'student5','address5',523456,'05-MAY-1990' ,12000,10000,'I'); 4. insert into installment values(12345,5000,'22-AUGUST-2010','U'); insert into installment values(22345,20000,'23-AUGUST-2010','P'); insert into installment values(32345,2000,'24-AUGUST-2010','U'); insert into installment values(42345,12000,'24-SEPTEMBER-2010','P'); insert into installment values(52345,1000,'29-SEPTEMBER-2010','U'); 5. insert into course_taken values(12345,'c1','29- SEPTEMBER-2010','F','AN','GOOD'); insert into course_taken values(22345,'c1','30- SEPTEMBER-2010','F','FN','GOOD');
  • 3. insert into course_taken values(32345,'c2','30- SEPTEMBER-2010','F','FN','GOOD'); insert into course_taken values(42345,'c3','28- SEPTEMBER-2010','P','AN','GOOD'); insert into course_taken values(52345,'c4','30- SEPTEMBER-2010','P','AN','GOOD'); QUERIES: Q1. Retrieve name and course no. of all students. select student.name,course_taken.course_no from student,course_taken where student.prospectus_no=course_taken.prospectus_no; NAME COUR -------------------- ---- student1 c1 student2 c1 student3 c2 student4 c3 student5 c4 Q2. List the names of students who have paid the full amount at the time of admission select name from student where total_amt=amt_paid; NAME -------------------- student2 student4
  • 4. Q3. Find the names of students starting with A. select * from student where name like 'A%'; no rows selected Q4. Print the names of students whose total amount is not equal to amount due. select student.name from student where amt_paid not in(select amt_paid from student where total_amt=amt_paid); NAME -------------------- student1 student3 student5 Q5. Count the number of students who have joined in current year, current month. select count(*) from course_taken where start_dt like '___SEP_10'; COUNT(*) ---------- 5
  • 5. Q6. Determine the maximum and minimum course fees. select max(fees),min(fees) from course_fee; MAX(FEES) MIN(FEES) ----------- --------- 14000 8000 Q7. Increase the fee of Oracle by 50%. update course_fee set fees=1.5*fees where fees in(select course_fee.fees from course_fee,course where course.course_no=course_fee.course_no and course.course_name='ORACLE'); Q8. Print the details of courses whose fees are between 5000 and 10000. select course.course_no,course.course_name,course_fee.fees,course_fee.full_part from course,course_fee where course.course_no=course_fee.course_no and (course_fee.fees>5000 and course_fee.fees<10000); COUR COURSE_NAME FEES F ---- -------------------- ---------- - c2 UNIX 8000 F Q9. Display the admission date in DD-MONTH-YY format select TO_CHAR(start_dt,'dd-month-yyyy') as start_dt from course_taken; START_DT -----------------
  • 6. 29-september-2010 30-september-2010 30-september-2010 28-september-2010 30-september-2010 Q10. Find out in which course maximum number of students have taken admission. select course.course_name from course,course_taken where course.course_no=course_taken.course_no group by course.course_name having count(course_taken.prospectus_no)>=all (select count(prospectus_no) from course_taken group by course_no); COURSE_NAME -------------------- LINUX Q11. Change the course_name from Unix to Unix OS. update course set course_name='UNIX OS' where course_name='UNIX'; Q12. Get the sum of amount to be collected from students in this month. select sum(student.total_amt-student.amt_paid) from student,installment where student.prospectus_no=installment.prospectus_no and installment.due_dt like '___SEP_10'; SUM(STUDENT.TOTAL_AMT-STUDENT.AMT_PAID) ---------------------------------------
  • 7. 2000 . Q13. Find out in which course maximum number of students have taken admission in the current month. select course.course_name from course,course_taken where course.course_no=course_taken.course_no and start_dt like '___SEP_10' group by course.course_name having count(course_taken.prospectus_no)>=all (select count(prospectus_no) from course_taken group by course_no); COURSE_NAME -------------------- LINUX Q14. Select the students who have not yet paid full amount of fees. select name from student where total_amt>amt_paid; NAME -------------------- student1 student3 student5