SlideShare uma empresa Scribd logo
1 de 8
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados (20)

Two Dimensional Array
Two Dimensional ArrayTwo Dimensional Array
Two Dimensional Array
 
Factorial of a number in python
Factorial of a number in pythonFactorial of a number in python
Factorial of a number in python
 
Array in c programming
Array in c programmingArray in c programming
Array in c programming
 
Chapter-14 Grouping Records, Joins in SQL.pdf
Chapter-14 Grouping Records, Joins in SQL.pdfChapter-14 Grouping Records, Joins in SQL.pdf
Chapter-14 Grouping Records, Joins in SQL.pdf
 
Sql Commands
Sql CommandsSql Commands
Sql Commands
 
Ref cursor
Ref cursorRef cursor
Ref cursor
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Array
ArrayArray
Array
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
BINARY SEARCH TREE
BINARY SEARCH TREE BINARY SEARCH TREE
BINARY SEARCH TREE
 
SQL .pptx
SQL .pptxSQL .pptx
SQL .pptx
 
Python: Basic Inheritance
Python: Basic InheritancePython: Basic Inheritance
Python: Basic Inheritance
 
Selection sort
Selection sortSelection sort
Selection sort
 
Matrices - Mathematics
Matrices - MathematicsMatrices - Mathematics
Matrices - Mathematics
 
Ds lab handouts
Ds lab handoutsDs lab handouts
Ds lab handouts
 
Presentation of array
Presentation of arrayPresentation of array
Presentation of array
 
Data structures using c
Data structures using cData structures using c
Data structures using c
 
Merge sort
Merge sortMerge sort
Merge sort
 
Data Analysis with Python Pandas
Data Analysis with Python PandasData Analysis with Python Pandas
Data Analysis with Python Pandas
 
SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question Bank
 

Destaque

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
 

Destaque (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
 

Semelhante a Sql

WRITE A C++ PROGRAM TO IMPLEMENT THE FOLLOWING.pdf
WRITE A C++ PROGRAM TO IMPLEMENT THE FOLLOWING.pdfWRITE A C++ PROGRAM TO IMPLEMENT THE FOLLOWING.pdf
WRITE A C++ PROGRAM TO IMPLEMENT THE FOLLOWING.pdfindiaartz
 
[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
 
import java-lang-Math- class Point { Point() { this-x - 0.docx
import java-lang-Math- class Point {      Point() {         this-x - 0.docximport java-lang-Math- class Point {      Point() {         this-x - 0.docx
import java-lang-Math- class Point { Point() { this-x - 0.docxBlake0FxCampbelld
 

Semelhante a Sql (8)

BScPLSQL.pdf
BScPLSQL.pdfBScPLSQL.pdf
BScPLSQL.pdf
 
WRITE A C++ PROGRAM TO IMPLEMENT THE FOLLOWING.pdf
WRITE A C++ PROGRAM TO IMPLEMENT THE FOLLOWING.pdfWRITE A C++ PROGRAM TO IMPLEMENT THE FOLLOWING.pdf
WRITE A C++ PROGRAM TO IMPLEMENT THE FOLLOWING.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
 
import java-lang-Math- class Point { Point() { this-x - 0.docx
import java-lang-Math- class Point {      Point() {         this-x - 0.docximport java-lang-Math- class Point {      Point() {         this-x - 0.docx
import java-lang-Math- class Point { Point() { this-x - 0.docx
 
Quiz using C++
Quiz using C++Quiz using C++
Quiz using C++
 
DECLARE example
DECLARE exampleDECLARE example
DECLARE example
 

Sql

  • 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