Workbook: For The Academy Training Program With TLS-ET
Workbook: For The Academy Training Program With TLS-ET
Workbook
Admin
Employee ID
[Company E-mail]
February 6, 2022
Version: 3
Table of Contents
About me...............................................................................................................................................3
Exercise - 1.............................................................................................................................................4
Exercise - 2...........................................................................................................................................56
Exercise - 3...........................................................................................................................................74
Exercise - 4...........................................................................................................................................93
Exercise - 5.........................................................................................................................................142
Exercise - 6.........................................................................................................................................157
About me
Declaration
I declare that this workbook and reports are my own work, based on my personal
study and/or research and that I have not copied in part or whole or otherwise
plagiarized the work of other trainees and/or persons.
Name: Admin
Date: [Publish Date]
Exercise - 1
Problem Statement:
1. Find out the selling cost avg for packages developed in pascal
Solution:
select AVG(Scost) AS SELLINGCOST from Software where Dev_In='PASCAL'
Input:
Output:
SELLINGCOST
3066.33333333333
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
2. Display name, ages of all programmers
Solution:
select pname,year(getdate()) -year(dob) as Age from Programmer
Input:
Output:
ANAND 55
ALTAF 57
JULIANA 53
KAMALA 53
MARY 51
NELSON 36
PATRICK 56
QADIR 56
RAMESH 54
REBECCA 54
REMITHA 51
REVATHI 52
VIJAYA 56
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
3. Display the names of those who have done the Dap course
Solution:
SELECT Pname FROM Software WHERE Dev_In='DBASE';
Input:
Output:
Pname
KAMALA
RAMESH
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
4. Display the name and DOB of all programmers born in January
Solution:
SELECT PNAME,Dob FROM Programmer WHERE MONTH(Dob)=1
Input:
Output:
PNAME Dob
JULIANA 1968-01-31
REBECCA 1967-01-01
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
5. What is the highest no. of copies sold by a package
Solution:
SELECT * FROM Software WHERE SOLD =(SELECT MAX(Sold) FROM SOFTWARE);
Input:
Output:
Pname Title Dev_In Scost Dcost Sold
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
6. Display lowest course fee
Solution:
SELECT MIN(COST) FROM STUDIES
Input:
Output:
(No column name)
4500
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
7. How many programmers done a PGDCA course
Solution:
select p.Pname from Programmer p,Studies s
where p.Pname=s.Pname and s.Course='PGDCA'
Input:
Output:
Pname Dob Doj Sex Prof1 Prof2 Salary
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
8.How much revenue has been earned through sales of packages developed in C
Solution:
SELECT sum(Scost) as Total from Software where Dev_In='C';
Input:
Output:
Total
3525
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
9. Display the details of the software developed by ramesh
Solution:
SELECT DEV_IN FROM Software WHERE Pname='RAMESH';
Input:
Output:
DEV_IN
DBASE
PASCAL
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
10. How many programmers studied at sabhari
Solution:
SELECT P.* from Programmer p,Studies s
where P.Pname=S.Pname AND s.Splace='SABHARI';
Input:
Output:
Pname Dob Doj Sex Prof1 Prof2 Salary
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
11.Display details of packages whose sales crossed the 2000 mark
Solution:
SELECT * FROM Software WHERE Scost>2000
Input:
Output:
Pname Title Dev_In Scost Dcost Sold
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement
13. What is the costliest software development in the basic
Solution:
select * from Software where Dev_In='Basic' and Dcost=(select max(Dcost) from
Software where Dev_In='Basic')
Input:
Output:
Pname Title Dev_In Scost Dcost Sold
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
14. How many packages developed in dbase
Solution:
select count(title) as TotalPackages from Software where Dev_In='DBASE'
Input:
Output:
TotalPackages
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
15. How many programmers studied in pragathi
Solution:
select count(Pname) as Total from Studies where Splace='PRAGATHI'
Input:
Output:
Total
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
16. How many programmers payed 5000 to 10000 for their course
Solution:
SELECT * FROM Studies WHERE Cost BETWEEN 5000 AND 10000
Input:
Output:
Pname Splace Course Cost
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
17. What is AVG course fee
Solution:
SELECT AVG(Cost) FROM Studies
Input:
Output:
AverageFee
11015
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
18. Display the details of the programmers knowing C
Solution:
select * from Programmer where Prof1='C' or Prof2='C'
Input:
Output:
AverageFee
11015
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
19. How many programmers know either cobol or pascal
Solution:
select * from Programmer where Prof1 IN ('COBOL','PASCAL') OR Prof2
IN('COBOL','PASCAL')
Input:
Output:
Pname Dob Doj Sex Prof1 Prof2 Salary
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
20. How Many programmers don’t know pascal and C
Solution:
select * from Programmer where Prof1 NOT IN ('PASCAL','C') AND Prof2 NOT
IN('PASCAL','C')
Input:
Output:
Pname Dob Doj Sex Prof1 Prof2 Salary
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
21. How old is the oldest male programmer?
Solution:
select max(YEAR(Doj)-Year(Dob)) Older from Programmer WHERE SEX = 'M';
Input:
Output:
Older
26
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
22. What is the avg age of female programmer
Solution:
select Avg(YEAR(Doj)-Year(Dob)) Older from Programmer where Sex='F'
Input:
Output:
Older
23
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
23.Calculate the experience in years for each programmer and display with their
names in
--descending order
Solution:
select Pname,(YEAR(Doj)-Year(Dob)) Year from Programmer order by Pname desc
Input:
Output:
Pname Year
VIJAYA 27
REVATHI 23
REMITHA 23
REBECCA 23
RAMESH 24
QADIR 26
PATRICK 25
NELSON 4
MARY 21
KAMALA 24
JULIANA 22
ANAND 26
ALTAF 26
Key Learnings:
Challenges faced & rectification efforts:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
24. Who are the programmers who celebrate their birthday during the current month?
Solution:
select Pname from Programmer where Month(Dob)=datepart(mm,getdate())
Input:
Output:
Pname
REVATHI
VIJAYA
Key Learnings:
Completed Date:
Problem Statement:
25. How many female programmers are there?
Solution:
select count(Pname) as TotalFemales from Programmer where Sex='F'
Input:
Output:
TotalFemales
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
26. What are the languages studied by the male programmers?
Solution:
select CONCAT(Prof1,',',Prof2) as Languages from Programmer where Sex='M'
Input:
Output:
Languages
PASCAL,BASIC
CLIPPER,COBOL
COBOL,DBASE
PASCAL,CLIPPER
ASSEMBLY,C
PASCAL,DBASE
Key Learnings:
Completed Date:
Problem Statement:
27. What is the AVG salary
Solution:
select Avg(salary) as AverageSalary from Programmer;
Input:
Output:
AverageSalary
3169.23076923077
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
28. How many people draw salary 2000-4000
Solution:
select count(pname) as People from Programmer where Salary between 2000 and 4000;
Input:
Output:
People
12
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
29. Display the details of those who don’t know clipper, cobol or pascal
Solution:
select * from Programmer where Prof1 Not in ('CLIPPER','COBOL','PASCAL') or Prof2
Not in('CLIPPER','COBOL','PASCAL') ;
Input:
Output:
Pname Dob Doj Sex Prof1 Prof2 Salary
Key Learnings:
Challenges faced & rectification efforts:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
30.Display the cost of package developed by each programmer
Solution:
select P.Pname, S.Cost from Programmer P,Studies S
where p.Pname=S.Pname;
Input:
Output:
Pname Cost
ANAND 4500
ALTAF 7200
JULIANA 22000
KAMALA 5000
MARY 4600
NELSON 6200
PATRICK 5200
QADIR 14000
RAMESH 4500
REBECCA 11000
REMITHA 6000
REVATHI 5000
VIJAYA 48000
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
31. Display the sales values of the packages developed by each programmer
Solution:
select P.Pname, S.Scost As Sales from Software S,Programmer P
where S.Pname=P.Pname
Input:
Output:
Pname Sales
ANAND 399
ANAND 7500
JULIANA 3000
KAMALA 9000
MARY 18000
PATRICK 4500
QADIR 300
QADIR 750
QADIR 1900
RAMESH 12000
RAMESH 599
REMITHA 725
REMITHA 2500
REVATHI 1100
REVATHI 3200
VIJAYA 900
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
32. Display the no. of packages sold by each programmer
Solution:
SELECT Pname AS PRNAME,COUNT(TITLE)AS NOOFPACK
FROM SOFTWARE
GROUP BY Pname
Input:
Output:
PRNAME NOOFPACK
ANAND 2
JULIANA 1
KAMALA 1
MARY 1
PATRICK 1
QADIR 3
RAMESH 2
REMITHA 2
REVATHI 2
VIJAYA 1
Key Learnings:
Challenges faced & rectification efforts:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
33. Display the sales cost of the packages developed by each programmer language
wise
Solution:
SELECT SUM(SCOST) AS SELLCOST
FROM SOFTWARE
GROUP BY DEV_IN
Input:
Output:
SELLCOST
3250
3599
3525
300
7500
21000
18000
9199
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
34. Display each language name with AVG development cost, AVG selling cost and AVG
price per --copy
Solution:
SELECT DEV_IN AS LANGUAGE,AVG(DCOST) AS AVGDEVCOST,AVG(SCOST) AS
AVGSELLCOST,AVG(SCOST) AS PRICEPERCPY
FROM SOFTWARE
GROUP BY DEV_IN
Input:
Output:
LANGUAGE AVGDEVCOST AVGSELLCOST PRICEPERCPY
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
35. Display each institute name with no. of course, avg. cost per course
Solution:
SELECT SPLACE AS INSTITUTE,COUNT(COURSE) AS NOOFCOURS,AVG(COST) AS AVGCOSTPERCOUR
FROM STUDIES
GROUP BY SPLACE
Input:
Output:
INSTITUTE NOOFCOURS AVGCOSTPERCOUR
APPLE 1 14000
BDPS 2 27000
BITS 1 22000
BPILLANI 1 11000
COIT 1 7200
PRAGATHI 2 5600
SABHARI 5 4760
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
37. Display each institute name for with no. of students
Solution:
SELECT SPLACE AS INSTITUTE,COUNT(Pname) AS NOOFSTUD
FROM STUDIES
GROUP BY SPLACE
Input:
Output:
INSTITUTE NOOFSTUD
APPLE 1
BDPS 2
BITS 1
BPILLANI 1
COIT 1
PRAGATHI 2
SABHARI 5
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
38.Display names of male and female programmers, gender also
Solution:
SELECT Pname AS PRNAME,SEX AS SEX
FROM PROGRAMMER
ORDER BY SEX
Input:
Output:
PRNAME SEX
JULIANA F
KAMALA F
MARY F
REBECCA F
REMITHA F
REVATHI F
VIJAYA F
NELSON M
PATRICK M
QADIR M
RAMESH M
ANAND M
ALTAF M
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
39. Display the name of programmers and their packages
Solution:
SELECT Pname AS PRNAME,TITLE AS PACKAGE
FROM SOFTWARE
ORDER BY Pname
Input:
Output:
PRNAME PACKAGE
ANAND PARACHUTES
QADIR READ ME
QADIR VACCINES
REMITHA PC UTILITIES
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
40. Display the no. of packages in each language expect C and C++
Solution:
SELECT COUNT(TITLE) AS NOOFPACK,DEV_IN AS LANGUAGE
FROM SOFTWARE
where DEV_IN not in('C','C++')
GROUP BY DEV_IN
Input:
Output:
NOOFPACK LANGUAGE
2 ASSEMBLY
2 BASIC
2 COBOL
2 DBASE
1 ORACLE
3 PASCAL
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
41. Display the no. of packages in each language for which development cost is less
than 1000
Solution:
SELECT COUNT(TITLE) AS NOOFPACK,DEV_IN AS LANGUAGE
FROM SOFTWARE
WHERE DCOST<1000 GROUP BY DEV_IN
Input:
Output:
NOOFPACK LANGUAGE
1 C
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
42. Display the total SCOST, DCOST AND Amount to be recovered for each programmer
for those
--whose cost has not yet been recovered
Solution:
SELECT SUM(SCOST), SUM(DCOST), SUM(DCOST-(SOLD*SCOST)) FROM SOFTWARE GROUP BY pNAME
HAVING SUM(DCOST)>SUM(SOLD*SCOST)
Input:
Output:
(No column name) (No column name) (No column name)
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
43. Display AVG difference between SCOST, DCOST for each package
Solution:
SELECT DEV_IN AS LANGUAGE,AVG(DCOST - SCOST) AS DIFF FROM SOFTWARE GROUP BY DEV_IN
Input:
Output:
LANGUAGE DIFF
ASSEMBLY 3875
BASIC 2250.5
C 1858.33333333333
C++ 900
COBOL 8000
DBASE 1250
ORACLE 67000
PASCAL 28767
Key Learnings:
Challenges faced & rectification efforts:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
44. Display highest, lowest and average salaries for those earning more than 2000
Solution:
SELECT MAX(SALARY), MIN(SALARY), AVG(SALARY)
FROM PROGRAMMER
WHERE SALARY > 2000
Input:
Output:
(No column name) (No column name) (No column name)
Key Learnings:
Completed Date:
Problem Statement:
45. Who is the highest paid C programmer?
Solution:
SELECT * FROM PROGRAMMER
WHERE SALARY=(SELECT MAX(SALARY)
FROM PROGRAMMER WHERE PROF1 = 'C' OR PROF2 = 'C')
Input:
Output:
Pname Dob Doj Sex Prof1 Prof2 Salary
Key Learnings:
Completed Date:
Problem Statement:
46. Who is the highest paid female programmer?
Solution:
SELECT * FROM PROGRAMMER
WHERE SALARY=(SELECT MAX(SALARY)
FROM PROGRAMMER
where SEX = 'F')
Input:
Output:
Pname Dob Doj Sex Prof1 Prof2 Salary
Key Learnings:
Completed Date:
Problem Statement:
47. Display the name of the highest paid programmers for each language
Solution:
SELECT DISTINCT Pname, SALARY, PROF1
FROM PROGRAMMER WHERE (Salary) IN (SELECT MAX(SALARY)
FROM PROGRAMMER) and (PROF1) in (select max(PROF1) from Programmer
GROUP BY PROF1)
Input:
Output:
Pname SALARY PROF1
Key Learnings:
Completed Date:
Problem Statement:
48. Who is the least experience programmer?
Solution:
SELECT (datepart(yy,GETDATE())-datepart(yy,Doj)) as EXP,pname
FROM PROGRAMMER where datepart(yy,GETDATE())-datepart(yy,Doj) in (select
min(datepart(yy,GETDATE())-datepart(yy,Doj))as EXP FROM PROGRAMMER)
Input:
Output:
EXP pname
28 REMITHA
Key Learnings:
Completed Date:
Problem Statement:
49. Who is the most experience male programmer knowing pascal
Solution:
SELECT (datepart(yy,GETDATE())-datepart(yy,Doj)) as EXP,pname
FROM PROGRAMMER where Sex='M' and datepart(yy,GETDATE())-datepart(yy,Doj) in
(select max(datepart(yy,GETDATE())-datepart(yy,Doj))as EXP FROM PROGRAMMER)
Input:
Output:
EXP pname
32 NELSON
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
50. Which language is known by only one programmer?
Solution:
SELECT PROF1
FROM PROGRAMMER
GROUP BY PROF1
HAVING PROF1 NOT IN
(SELECT PROF2 FROM PROGRAMMER)
AND COUNT(PROF1)=1
UNION
SELECT PROF2
FROM PROGRAMMER
GROUP BY PROF2
HAVING PROF2 NOT IN
(SELECT PROF1 FROM PROGRAMMER)
AND COUNT(PROF2)=1;
Input:
Output:
EXP pname
32 NELSON
Key Learnings:
Challenges faced & rectification efforts:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Exercise - 2
Problem Statement:
1. Calculate the amount to be recovered for those packages whose development cost
has not yet
--been recovered?
Solution:
SELECT (DCOST-(SCOST*SOLD)),TITLE
FROM SOFTWARE where (Dev_In='COBOL' and Pname='JULIANA')
Input:
Output:
(No column name) TITLE
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
2. List the packages, which have not been sold so far?
Solution:
select title from software where sold=0
Input:
Output:
title
INVENTORY CONTROL
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
3. Find out the cost of the software developed by Mary?
Solution:
select sum(sold*Scost) from Software where Pname='Mary'
Input:
Output:
(No column name)
72000
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
4. Display the institute names from the studies table without the duplicates
Solution:
select distinct(splace) from Studies
Input:
Output:
splace
APPLE
BDPS
BITS
BPILLANI
COIT
PRAGATHI
SABHARI
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
5. How many different courses are mentioned in the studies table?
Solution:
select distinct(course) from Studies
Input:
Output:
course
DAP
DCA
DCP
DCS
HDCP
MCA
PGDCA
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
6. Display the names of the programmers whose names contain 2 occurrences of the
letter ‘A’
Solution:
SELECT pNAME FROM PROGRAMMER WHERE pNAME LIKE '%A%A%'
Input:
Output:
pNAME
ANAND
ALTAF
JULIANA
KAMALA
VIJAYA
Key Learnings:
Completed Date:
Problem Statement:
7. Display the names of the programmers whose names contains 5 characters
Solution:
SELECT pNAME FROM PROGRAMMER WHERE pNAME LIKE '_____' and LEN(pname)=5
Input:
Output:
pNAME
ANAND
ALTAF
QADIR
Key Learnings:
Completed Date:
Problem Statement:
8. How many female programmers knowing COBOL have more than 2yrs experience
Solution:
select count(DATEPART(yy,Doj)-DATEPART(yy,Dob)) from Programmer where
DATEPART(yy,Doj)-DATEPART(yy,Dob)>5 and Sex='F' and Prof1 in('COBOL')
or prof2 in ('COBOL')
Input:
Output:
(No column name)
Key Learnings:
Completed Date:
Problem Statement:
9. What is the length of the shortest name in the programmer table
Solution:
select min(len(pname)) from Programmer;
Input:
Output:
(No column name)
Key Learnings:
Completed Date:
Problem Statement:
10. What is the average development cost of a package developed in COBOL
Solution:
select avg(Dcost) from Software where Dev_in='COBOL'
Input:
Output:
(No column name)
11750
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
11. Display the name, sex, dob (dd/mm/yy format), DOJ (dd/mm/yy format) for all the
programmers
Solution:
select pname,sex,FORMAT (Dob, 'dd/MM/yy') as DOB,Format(Doj,'dd/MM/yy') from
Programmer
Input:
Output:
pname sex DOB (No column name)
Key Learnings:
Status
Description Efforts (Solved/Not
solved)
Completed Date:
Problem Statement:
12. What is the amount paid in salaries of the male programmers who don’t know
COBOL?
Solution:
SELECT SALARY AS SALOFPR
FROM PROGRAMMER
WHERE SEX='M'
AND (PROF1!='COBOL'
OR PROF2!='COBOL')
Input:
Output:
SALOFPR
3200
2800
2500
2800
3000
3200
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
13. Display the title, scost, dcost and difference between scost and dcost in
descending order of
--difference
Solution:
SELECT TITLE AS SOFTNAME,SCOST AS SOFTCOST,DCOST AS DEVCOST,DCOST - SCOST DIFF FROM
SOFTWARE
ORDER BY 4 DESC
Input:
Output:
SOFTNAME SOFTCOST DEVCOST DIFF
Key Learnings:
Challenges faced & rectification efforts:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
14. Display the names of the packages whose names contain more than 1 word
Solution:
SELECT TITLE AS PACKAGES
FROM SOFTWARE
WHERE TITLE LIKE '%%'
Input:
Output:
PACKAGES
PARACHUTES
INVENTORY CONTROL
PAYROLL PACKAGE
FINANCIAL ACC.S/W
CODE GENERATION
READ ME
BOMBS AWAY
VACCINES
HOTEL MANAGEMENT
DEAD LEE
PC UTILITIES
HOSPITAL MANAGEMENT
QUIZ MASTER
ISR EDITION
Key Learnings:
Completed Date:
Problem Statement:
15. Display the name, dob, doj of those months of birth and month of joining are
same
Solution:
SELECT pNAME AS PRNAME
FROM PROGRAMMER
WHERE datepart(mm,dob)=datepart(mm,doj)
Input:
Output:
PRNAME
ANAND
REMITHA
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Exercise - 3
Problem Statement:
1. Display the cost of the package developed by each programmer
Solution:
SELECT Pname AS PRNAME,SUM(DCOST) AS TOTCOST
FROM SOFTWARE
GROUP BY Pname
Input:
Output:
PRNAME TOTCOST
ANAND 22000
JULIANA 3500
KAMALA 20000
MARY 85000
PATRICK 20000
QADIR 9600
RAMESH 8000
REMITHA 11000
REVATHI 77100
VIJAYA 700
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
2. Display the sales values of the packages developed by each programmer
Solution:
SELECT Pname AS PRNAME, SUM(SCOST*SOLD) AS SALESVAL
FROM SOFTWARE
GROUP BY pNAME
Input:
Output:
PRNAME SALESVAL
ANAND 84657
JULIANA 0
KAMALA 63000
MARY 72000
PATRICK 103500
QADIR 73350
RAMESH 91727
REMITHA 51975
REVATHI 50200
VIJAYA 5400
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
3. Display the number of packages sold by each programmer
Solution:
SELECT Pname AS PRNAME,COUNT(TITLE) AS TOTPACK
FROM SOFTWARE
GROUP BY pNAME
Input:
Output:
PRNAME TOTPACK
ANAND 2
JULIANA 1
KAMALA 1
MARY 1
PATRICK 1
QADIR 3
RAMESH 2
REMITHA 2
REVATHI 2
VIJAYA 1
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
4. Display the sales cost of the packages developed by each programmer
Solution:
SELECT SUM(SCOST) AS SELLCOST
FROM SOFTWARE
GROUP BY DEV_IN
Input:
Output:
SELLCOST
3250
3599
3525
300
7500
21000
18000
9199
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
5. Display each language name with average development cost, average selling cost
and average
--price per copy
Solution:
SELECT DEV_IN AS LANGUAGE,AVG(DCOST) AS AVGDEVCOST,AVG(SCOST) AS
AVGSELLCOST,AVG(SCOST) AS PRICEPERCPY
FROM SOFTWARE
GROUP BY DEV_IN
Input:
Output:
LANGUAGE AVGDEVCOST AVGSELLCOST PRICEPERCPY
Key Learnings:
Completed Date:
Problem Statement:
6. Display each programmer’s name, costliest package and cheapest packages developed
by him /
--her.
Solution:
SELECT Pname PRNAME,MIN(DCOST) CHEAPEST,MAX(DCOST) COSTLIEST
FROM SOFTWARE
GROUP BY pNAME
Input:
Output:
PRNAME CHEAPEST COSTLIEST
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
7. Display each institute name with number of courses, average cost per course
Solution:
SELECT SPLACE AS INSTITUTE,COUNT(COURSE) AS NOOFCOURS,AVG(COST) AS AVGCOSTPERCOUR
FROM STUDIES
GROUP BY SPLACE
Input:
Output:
INSTITUTE NOOFCOURS AVGCOSTPERCOUR
APPLE 1 14000
BDPS 2 27000
BITS 1 22000
BPILLANI 1 11000
COIT 1 7200
PRAGATHI 2 5600
SABHARI 5 4760
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
8. Display each Institute name with number of students
Solution:
SELECT SPLACE AS INSTITUTE,COUNT(Pname) AS NOOFSTUD
FROM STUDIES
GROUP BY SPLACE
Input:
Output:
INSTITUTE NOOFSTUD
APPLE 1
BDPS 2
BITS 1
BPILLANI 1
COIT 1
PRAGATHI 2
SABHARI 5
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
9. Display the names of male and female programmers
Solution:
SELECT pNAME AS PRNAME,SEX AS SEX
FROM PROGRAMMER
ORDER BY SEX
Input:
Output:
PRNAME SEX
JULIANA F
KAMALA F
MARY F
REBECCA F
REMITHA F
REVATHI F
VIJAYA F
NELSON M
PATRICK M
QADIR M
RAMESH M
ANAND M
ALTAF M
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
10. Display the programmer’s name and their packages
Solution:
SELECT Pname AS PRNAME,TITLE AS PACKAGE
FROM SOFTWARE
ORDER BY pNAME
Input:
Output:
PRNAME PACKAGE
ANAND PARACHUTES
QADIR READ ME
QADIR VACCINES
RAMESH HOTEL MANAGEMENT
REMITHA PC UTILITIES
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
11. Display the number of packages in each language except C and C++
Solution:
SELECT COUNT(TITLE) AS NOOFPACK,DEV_IN AS LANGUAGE
FROM SOFTWARE
where DEV_IN not in('C','C++')
GROUP BY DEV_IN
Input:
Output:
NOOFPACK LANGUAGE
2 ASSEMBLY
2 BASIC
2 COBOL
2 DBASE
1 ORACLE
3 PASCAL
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
12. Display the number of packages in each language for which development cost is
less than 1000
Solution:
SELECT COUNT(TITLE) AS NOOFPACK,DEV_IN AS LANGUAGE
FROM SOFTWARE
WHERE DCOST<1000 GROUP BY DEV_IN
Input:
Output:
NOOFPACK LANGUAGE
1 C
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
13. Display the average difference between SCOST and DCOST for each language
Solution:
SELECT DEV_IN AS LANGUAGE,AVG(DCOST - SCOST) AS DIFF FROM SOFTWARE GROUP BY DEV_IN
Input:
Output:
LANGUAGE DIFF
ASSEMBLY 3875
BASIC 2250.5
C 1858.33333333333
C++ 900
COBOL 8000
DBASE 1250
ORACLE 67000
PASCAL 28767
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
14. Display the total SCOST, DCOST and amount to be recovered for each programmer
for those
--whose DCOST has not yet been recovered
Solution:
SELECT SUM(SCOST), SUM(DCOST), SUM(DCOST-(SOLD*SCOST)) FROM SOFTWARE GROUP BY Pname
HAVING SUM(DCOST)>SUM(SOLD*SCOST)
Input:
Output:
(No column name) (No column name) (No column name)
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
15. Display the highest, lowest and average salaries for those earning more than
2000
Solution:
SELECT MAX(SALARY), MIN(SALARY), AVG(SALARY)
FROM PROGRAMMER
WHERE SALARY > 2000
Input:
Output:
(No column name) (No column name) (No column name)
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Exercise - 4
Problem Statement:
1. Who is the most experienced programmer knowing pascal?
Solution:
SELECT (datepart(yy,GETDATE())-datepart(yy,Doj)) as EXP,pname
FROM PROGRAMMER where datepart(yy,GETDATE())-datepart(yy,Doj) in
(select max(datepart(yy,GETDATE())-datepart(yy,Doj))as EXP FROM PROGRAMMER)
Input:
Output:
EXP pname
32 NELSON
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
2. Which course has been done by most of the students?
Solution:
select course,count(pname) as total from Studies group by course
Input:
Output:
course total
DAP 2
DCA 4
DCP 1
DCS 1
HDCP 1
MCA 1
PGDCA 3
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
3. Which course has the lowest selling cost?
Solution:
select * from Studies where Cost=(select min(cost) from Studies)
Input:
Output:
Pname Splace Course Cost
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
4. Display the courses whose fees are within 1000/- (+ or -) of the average fee
Solution:
select * from Studies where Cost=(select avg(cost) from Studies)
Input:
Output:
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
5. Who developed the package that has sold the least number of copies
Solution:
SELECT pNAME,SOLD
FROM SOFTWARE
WHERE SOLD = (SELECT MIN(SOLD) FROM SOFTWARE)
Input:
Output:
pNAME SOLD
JULIANA 0
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
6. Which language was used to develop most number of packages?
Solution:
SELECT DEV_IN FROM SOFTWARE
GROUP BY DEV_IN
HAVING MAX(DEV_IN) = (SELECT MAX(DEV_IN) FROM SOFTWARE)
Input:
Output:
DEV_IN
PASCAL
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
7. Display the names of the packages which have been sold less than the average
number of copies
Solution:
SELECT TITLE
FROM SOFTWARE
WHERE SOLD < (SELECT AVG(SOLD) FROM SOFTWARE)
Input:
Output:
TITLE
INVENTORY CONTROL
PAYROLL PACKAGE
FINANCIAL ACC.S/W
BOMBS AWAY
VACCINES
HOTEL MANAGEMENT
HOSPITAL MANAGEMENT
QUIZ MASTER
ISR EDITION
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
8. Who is the youngest male programmer born in 1965?
Solution:
SELECT Pname
FROM PROGRAMMER
WHERE DOB=(SELECT (MAX(DOB))
FROM PROGRAMMER
WHERE datepart(YYYY,Dob) LIKE '1965')
Input:
Output:
Pname
VIJAYA
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
9. In which year most, number of programmers born
Solution:
SELECT DISTINCT datepart(YYYY,Dob)
FROM PROGRAMMER
WHERE datepart(YYYY,dob) = (SELECT MIN(datepart(YYYY,Dob))
FROM PROGRAMMER)
Input:
Output:
(No column name)
1964
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
10. Which female programmer earning more than 3000/- does not know C, C++, ORACLE OR
DBASE
Solution:
select s.* from programmer p,software s
where p.pname=s.pname and salary>3000 and sex='F' and Dev_In not in ('C','C+
+','ORACLE','DBASE');
Input:
Output:
Pname Title Dev_In Scost Dcost Sold
Key Learnings:
Completed Date:
Problem Statement:
11. Which programmer has developed highest no of packages
Solution:
Input:
Output:
Pname
VIJAYA
Key Learnings:
Completed Date:
Problem Statement:
12. Who are the male programmers earning below the average salary of female
programmers
Solution:
SELECT Pname
FROM PROGRAMMER
WHERE SEX LIKE 'M'
AND SALARY < (SELECT(AVG(SALARY)) FROM PROGRAMMER WHERE SEX LIKE 'F')
Input:
Output:
Pname
ANAND
ALTAF
NELSON
PATRICK
QADIR
RAMESH
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
13. Display the details of those who are drawing salary.
Solution:
select a.Pname,a.salary from programmer a,programmer b where a.salary=b.salary and
a.Pname <> b.Pname
Input:
Output:
Pname salary
ANAND 3200
ALTAF 2800
JULIANA 3000
NELSON 2500
PATRICK 2800
QADIR 3000
RAMESH 3200
REBECCA 2500
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
14. Display the details of the software developed by the male programmers earning
more than 3000
Solution:
select s.*
from programmer p,software s
where p.pname=s.pname and salary>3000 and sex='m';
Input:
Output:
Pname Title Dev_In Scost Dcost Sold
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
15. Display the details of the software developed in C by female programmers of
Pragathi
Solution:
select s.*
from programmer p,software s,studies st
where p.pname=s.pname and s.pname=st.pname and sex='f' and splace='Pragathi';
Input:
Output:
Pname Title Dev_In Scost Dcost Sold
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
16. How many months it will take for each programmer to recover their cost of study
Solution:
select p.Pname,CEILING(cost/salary)
from programmer p,studies s
where s.pname=p.pname;
Input:
Output:
Pname (No column name)
ANAND 2
ALTAF 3
JULIANA 8
KAMALA 2
MARY 2
NELSON 3
PATRICK 2
QADIR 5
RAMESH 2
REBECCA 5
REMITHA 2
REVATHI 2
VIJAYA 14
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
-17. Display the details of the software developed in the language which is not the
programmers first
--proficiency
Solution:
select *
from software
where dev_in in(select distinct(prof2)
from programmer
where prof2 not in(select prof1
from programmer));
Input:
Output:
Pname Title Dev_In Scost Dcost Sold
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
18. Display the details of the software developed in the language which is neither
the first nor
--second proficiency of the programmer
Solution:
select s.*
from programmer p,software s
where s.Pname=p.Pname and (dev_in <> prof1 and dev_in <> prof2);
Input:
Output:
Pname Title Dev_In Scost Dcost Sold
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
19. Who are the programmers who joined on the same day?
Solution:
select a.pname,a.doj
from programmer a,programmer b
where a.doj=b.doj and a.pname <> b.pname;
Input:
Output:
pname doj
KAMALA 1992-01-02
REVATHI 1992-01-02
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
20. Display the programmers who are drawing same salary
Solution:
select P1.Pname,P2.Salary from Programmer P1,Programmer P2 where
p1.Salary=p2.Salary AND P1.Pname!=P2.Pname order by Salary asc
Input:
Output:
Pname Salary
NELSON 2500
REBECCA 2500
ALTAF 2800
PATRICK 2800
QADIR 3000
JULIANA 3000
ANAND 3200
RAMESH 3200
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
21. Which is the costliest package developed by a person with under 3 years of
experience
Solution:
select dev_in
from programmer p,software s
where p.pname=s.pname and dcost= (select max(s.dcost)
from programmer p, software s
where p.pname=s.pname)
Input:
Output:
dev_in
ORACLE
Key Learnings:
Completed Date:
Problem Statement:
22. What is the average salary for those whose software sales value is more than
50,000
Solution:
select avg(salary)
from programmer p,software s
where p .pname=s.pname and sold*scost>50000;
Input:
Output:
(No column name)
3350
Key Learnings:
Completed Date:
Problem Statement:
23. How many packages were developed by the person who developed the cheapest
package.
--Where did he / she study
Solution:
select count(*)
from programmer p,software s
where s .Pname=p.pname group by dev_in having min(dcost)=(select min(dcost) from
software);
Input:
Output:
(No column name)
Key Learnings:
Completed Date:
Problem Statement:
24. How many packages developed by female programmers earning more than the highest
paid
--male programmer
Solution:
select count(dev_in)
from programmer p,software s
where s.pname=p.pname and sex='f' and salary>(select max(salary)
from programmer p,software s
where s.pname=p.pname and sex='m');
Input:
Output:
(No column name)
Key Learnings:
Challenges faced & rectification efforts:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
25. How many packages were developed by the most experienced programmer from BDPS
Solution:
select count(*)
from software s,programmer p
where p.pname=s.pname group by doj having max(doj)=(select max(doj)
from studies st,programmer p, software s
where p.pname=s.pname and st.pname=p.pname and (splace='bdps'));
Input:
Output:
(No column name)
Key Learnings:
Challenges faced & rectification efforts:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
26. Write a query to display the last name, department number, and salary of any employee
whose department number and salary both match the department number and salary of any
employee who earns a commission.
Solution:
select Ename,Deptno,sal from Emp where comm !=0
Input:
Output:
Ename Deptno sal
ALLEN 30 1600
WARD 30 1250
MARTIN 30 1250
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
33. Write a query to display the last names of the employees who earn less than the average
salary in their departments.
Solution:
select * from emp e where sal<(select avg(sal) as avg from(select * from emp) e,
(select * from Dept) d
where e.deptno=d.Deptno
)
Input:
Output:
7369 SMITH 4 7902 1980-12-17 800 0 20
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
34. Write a query to display the last names of the employees who have one or more coworkers in
their departments with later hire dates but higher salaries.
Solution:
select * from emp where deptno in(select deptno from dept) order by sal
desc,hiredate
Input:
Output:
Empno Ename JobId Mgr Hiredate Sal Comm Deptno
Key Learnings:
Completed Date:
Problem Statement:
35. Write a query to display the department names of those departments whose total salary cost
is above one eighth (1/8) of the total salary cost of the whole company
Solution:
select * from emp where sal >( select 0.125*sum(sal) from Emp where deptno in
(10,20,30,40))
Input:
Output:
Empno Ename JobId Mgr Hiredate Sal Comm Deptno
Key Learnings:
Completed Date:
Problem Statement:
36. Write a query to display the last name, department number, and department name for all
employees
Solution:
select e.ename,d.deptno,d.Dname from emp e,dept d
where e.Deptno=d.Deptno
Input:
Output:
ename deptno Dname
SMITH 20 RESEARCH
ALLEN 30 SALES
WARD 30 SALES
JONES 20 RESEARCH
MARTIN 30 SALES
BLAKE 30 SALES
CLARK 10 ACCOUNTING
SCOTT 20 RESEARCH
KING 10 ACCOUNTING
TURNER 30 SALES
ADAMS 20 RESEARCH
JAMES 30 SALES
FORD 20 RESEARCH
MILLER 30 SALES
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
38. Write a query to display the employee last name, department name, location ID, and city of all
employees who earn a commission.
Solution:
select e.ename,d.Dname,d.Loc from emp e,dept d
where e.Deptno=d.Deptno and e.Comm !=0
Input:
Output:
ename Dname Loc
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
39. Display the employee last name and department name for all employees who have an a
(lowercase) in their last names
Solution:
select LOWER(e.ename),d.Dname from emp e,dept d
where e.Deptno=d.Deptno
Input:
Output:
smith RESEARCH
allen SALES
ward SALES
jones RESEARCH
martin SALES
blake SALES
clark ACCOUNTING
scott RESEARCH
king ACCOUNTING
turner SALES
adams RESEARCH
james SALES
ford RESEARCH
miller SALES
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
40. Write a query to display the last name, job, department number, and department name for all
employees who work in New York.
Solution:
select e.ename,d.Deptno,d.Dname from emp e,dept d
where e.Deptno=d.Deptno
and d.loc='NewYork'
Input:
Output:
ename Deptno Dname
CLARK 10 ACCOUNTING
KING 10 ACCOUNTING
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
41. Display all employees including King, who has no manager. Order the results by the employee
number.
Solution:
select * from emp order by Ename
Input:
Output:
Empno Ename JobId Mgr Hiredate Sal Comm Deptno
Key Learnings:
Challenges faced & rectification efforts:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
42. Create a query that displays employee last names, department numbers, and all the
employees who work in the same department as a given employee. Give each column an
appropriate labe
Solution:
Input:
Output:
Employee NameDepartment No
CLARK 10
KING 10
SMITH 20
JONES 20
SCOTT 20
ADAMS 20
FORD 20
ALLEN 30
WARD 30
MARTIN 30
BLAKE 30
TURNER 30
JAMES 30
MILLER 30
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
47. Job ID and total salary for every job ID for employees who report to the same manager
Solution:
select jobid,sum(sal) as salary from emp e group by jobid
Input:
Output:
jobid salary
1 5000
2 8275
3 6000
4 4150
5 5600
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
Solution:
select mgr,sum(sal) as salary from emp e group by mgr
Input:
Output:
mgr salary
5000
7566 6000
7698 6550
7782 1300
7788 1100
7839 8275
7902 800
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
1. Display the OrderID, CompanyName, Phone, ProductName, CityName, StateName,
--CountryName, Quantity placed by the clients whose email address is having using
--‘techmahindra.com’ domain
Solution:
select O.orderId,Cl.CompanyName,Cl.Phone,P.Productname,Cy.CityName,St.StateName from
Orders O,Clients Cl,Products P,CityMaster Cy,StateMaster St
where O.ClientID=Cl.ClientID and P.ProductID=O.OrderID and Cy.StateID=St.StateID
and Cy.CityID=Cl.CityID
Input:
Output:
orderId CompanyName Phone Productname CityName StateName
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
2. Display the sum of quantity of order for each client where the sum of quantity
range from 500
--to 1000. Along with CompanyName, Phone, CityName
Solution:
select Cl.ClientId,sum(O.quantity) from Orders O,Clients Cl group by Cl.ClientID
Input:
Output:
ClientId (No column name)
795371 3
795372 3
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
3. Display OrderID, CompanyName, Phone, ProductName whose product name is starting
with ‘M’
Solution:
select O.orderId,Cl.CompanyName,Cl.Phone,P.Productname from
Orders O,Clients Cl,Products P where O.ClientID=Cl.ClientID and
P.ProductID=O.OrderID and P.ProductName like 'M%'
Input:
Output:
orderId CompanyName Phone Productname
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
4. Display the total quantity of order for each cityid
Solution:
select sum(O.quantity) from Orders O,Clients Cs where
O.ClientID=Cs.ClientID
group by Cs.CityID
Input:
Output:
(No column name)
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
5. Create a view which displays all those orders whose Product Unit Price range
between 2000 to
--3000
Solution:
select O.* from Orders O ,Products P where O.ProductID=P.ProductID and P.UnitPrice
between 2000 and 3000
Input:
Output:
OrderID OrderDate ClientID ProductID Quantity ShippingDate
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
-6. Display Orders placed by the clients whose email address is created using
‘techmahindra.com’
--domain
Solution:
select O.* from Orders O,Clients C where O.ClientID=C.ClientID and email
like'___________techmahindra.com'
Input:
Output:
OrderID OrderDate ClientID ProductID Quantity ShippingDate
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
7. Display Orders placed by the clients who are located in the country name ‘India’
Solution:
select O.* from
Orders O,Clients Cl,Products P,CityMaster Cy,StateMaster St,CountryMaster CM
where O.ClientID=Cl.ClientID and P.ProductID=O.OrderID and Cy.StateID=St.StateID
and Cy.CityID=Cl.CityID and st.CountryID=CM.CountryID
and CM.CountryName like 'India'
Input:
Output:
OrderID OrderDate ClientID ProductID Quantity ShippingDate
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
8. Display Orders placed by the clients whose city name is starting with ‘H’
Solution:
select O.* from Orders O,Clients cs,CityMaster CM
where O.ClientID=cs.ClientID and cs.CityID=cm.CityID and Cm.CityName like 'H%'
Input:
Output:
OrderID OrderDate ClientID ProductID Quantity ShippingDate
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
9. Display all those products whose ReorderLevel range is not in 50 to 100
Solution:
select * from Products where ReorderLevel not between 50 and 100
Input:
Output:
ProductID ProductName UnitPrice LincensesInHand ReorderLevel
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
10. Display the average quantity of order for each product where the average
quantity is greater
--than 20
Solution:
select avg(O.Quantity) from Orders O where O.Quantity>20 group by ClientId
Input:
Output:
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
11. Display all those orders whose product name is having ‘studio’ word in them
Solution:
select o.* from Orders o,Products p where o.ProductID=p.ProductID and p.ProductName
like '%studio%'
Input:
Output:
OrderID OrderDate ClientID ProductID Quantity ShippingDate
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
12. Display the sum of quantity of order for each client where the sum of quantity
range from 500
--to 1000
Solution:
select cl.ClientId,cl.contactperson,sum(o.quantity) from Orders o,Products p,Clients
cl where o.ProductID=p.ProductID and cl.ClientID=o.ClientID
and p.UnitPrice>=500 and p.UnitPrice<=1000 group by cl.ClientID,cl.ContactPerson
Input:
Output:
ClientId contactperson(No column name)
795374 mark 10
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
13. Display all the Clients who are located in the city having city description as
“Garden City ”
Solution:
select cl.ClientId,cl.contactperson,cm.CityName from Clients cl,CityMaster cm where
cl.CityID=cm.CityID and cm.CityDesc='garden city'
Input:
Output:
ClientId contactpersonCityName
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
14. Display all the Clients who are located outside country name India
Solution:
select cl.*,com.CountryName from Clients cl,CityMaster cm,StateMaster
sm,CountryMaster com where cl.CityID=cm.CityID and sm.CountryID=com.CountryID
and cm.StateID=sm.StateID and com.CountryName='Usa'
Input:
Output:
ClientID CompanyName ContactPersonPhone EMAIL CityID CountryName
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
15. Display all those orders whose Product Unit Price range between 2000 to 3000
Solution:
select o.* from Orders o,Products p where p.UnitPrice>=2000 and p.UnitPrice<=3000
Input:
Output:
OrderID OrderDate ClientID ProductID Quantity ShippingDate
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Exercise - 6
Problem Statement:
1. Create a view which displays the city details with the following columns
--CityID, CityName, CityDescription, StateName, StateDescription, CountryName,
--CountryDescription
Solution:
create view vw_citystatecountry
as
select
cm.CityID,cm.CityDesc,sm.StateName,sm.StateDesc,com.CountryName,com.CountryDesc from
CityMaster cm,StateMaster sm,CountryMaster com
where cm.StateID=sm.StateID and com.CountryID=sm.CountryID;
Input:
select * from vw_citystatecountry
Output:
CityID CityDesc StateName StateDesc CountryName CountryDesc
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
2. Create a view which displays cities details belongs to the country ‘India’
Solution:
create view vw_cityindia
as
select cm.* from CityMaster cm,StateMaster sm,CountryMaster com
where cm.StateID=sm.StateID and com.CountryID=sm.CountryID and
com.CountryName='India'
Input:
select * from vw_cityindia
Output:
CityID CityName CityDesc StateID
c2 Hyderabad Metro s2
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
3. Create a stored procedure which takes the city name and displays all the orders
placed by the
--clients located in that given city name. If city name is not passed to that
procedure, it must display
--all those orders placed by the clients located in the city name starting with ‘N’.
Solution:
create procedure sp_cityname(@cityname varchar(50))
as
begin
if @cityname is not null
begin
Input:
exec sp_cityname 'vizag'
Output:
OrderID OrderDate ClientID ProductID Quantity ShippingDate
1 2021-12-07 00:00:00 795371 1 1 2021-12-08 00:00:00
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
-4. Create a stored procedure which displays the list of trigger names created on
the given table. If
--there are no triggers available on the given table, display ‘No triggers available
on
--<table_name>’
Solution:
create procedure sp_distrigger
as
begin
if exists(SELECT * FROM sys.triggers
)
SELECT
name,
is_instead_of_trigger
FROM
sys.triggers
WHERE
type = 'TR';
else
print 'no triggers'
end
Input:
exec sp_distrigger
Output:
no triggers
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
5. Create a procedure which displays the orders (along with CompanyName,
ProductName,
--UnitPrice, CityName) placed in the given range of dates.
Solution:
create procedure sp_disporders
as
begin
select o.*,cl.CompanyName,p.ProductName,p.unitprice,cm.cityname from Orders
o,Clients cl,Products p,CityMaster cm
where o.ProductID=p.ProductID and cl.ClientID=o.ClientID and cl.CityID=cm.CityID
order by OrderDate
end
Input:
exec sp_disporders
Output:
OrderID OrderDate ClientID ProductID Quantity ShippingDate
CompanyName ProductName unitprice cityname
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Problem Statement:
6. Create a function which takes the table name and returns the number of check constraints
create in it. If no check constraints available in that table then return 0
Solution:
Input:
select * from udf_chk('Products')
Output:
TechDB dbo PID_PK TechDB dbo Products PRIMARY KEY NO NO
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Time Taken for this exercise:
Completed Date:
Problem Statement:
7. Create a function which takes ProductName and Discount percentage and returns the UnitPrice
based on the discount percentage. Same function has to ensure whether the product exists or
not. If product exist return the UnitPrice based on the discount percentage else return zero.
Solution:
CREATE FUNCTION dbo.fnproducts(@productname varchar(max))
RETURNS varchar(max)
AS
BEGIN
DECLARE @tmp varchar(max)
IF (@productname is not null )
select @tmp=unitprice from Products where ProductName=@productname
ELSE
SELECT @tmp = 0
RETURN @tmp
END
Input:
print dbo.fnproducts('mobile')
Output:
3000.00
Key Learnings:
Completed Date:
Problem Statement:
8. Create a trigger which accepts Orders from users only between 9 AM and 6 PM
Solution:
CREATE TRIGGER Orders_trg_after ON Orders
After Insert,update,delete
AS
Begin
Input:
Output:
---------------------------
Microsoft SQL Server Management Studio
---------------------------
Error Message: The transaction ended in the trigger. The batch has been aborted.
C annot Perform
Correct the errors and retry or press ESC to cancel the change(s).
---------------------------
OK Help
---------------------------
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
9. Create a database trigger which allows users to create, alter, drop objects between 9 AM and 6
PM
Solution:
CREATE TRIGGER ddl_trig_database
ON ALL SERVER
FOR CREATE_TABLE
AS
Begin
GO
Input:
Output:
Msg 3609, Level 16, State 2, Line 23
The transaction ended in the trigger. The batch has been aborted.
Problem Statement:
10. Remove the Check constraint created on Order Date column, which checks whether the given
Order Date is greater or equal to Current Date.
Solution:
ALTER TABLE Orders
DROP CONSTRAINT SDate_CK;
Input:
Output:
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
11. Create a rule with a name ‘OrderDate_Rule’ with a rule that given date is greater than or equal
to current date. Apply the same to Orders table
Solution:
alter table orders
add constraint OrderDate_ck check (OrderDate>getdate())
Input:
Output:
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Key Learnings:
Completed Date:
Problem Statement:
12. Write the syntax for applying Rule to the columns while creating table
Solution:
-- Simple CREATE TABLE Syntax (common if not using options)
CREATE TABLE
{ database_name.schema_name.table_name | schema_name.table_name |
table_name }
( { <column_definition> } [ ,...n ] )
[ ; ]
Input:
Output:
Key Learnings:
Completed Date:
Problem Statement:
13. How to display the user defined rules created in DB using query window?
Solution:
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
Input:
Output:
Key Learnings:
Completed Date:
Problem Statement:
Write the syntax for binding a default to column while creating table
Solution:
Creates an object called a default. When bound to a column or an alias data type, a default
specifies a value to be inserted into the column to which the object is bound (or into all
columns, if of an alias data type), when no value is explicitly supplied during an insert.
Input:
Output:
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date:
Problem Statement:
15. How to display the user defined function names created in DB using query window?
Solution:
SELECT sm.object_id,
OBJECT_NAME(sm.object_id) AS object_name,
o.type,
o.type_desc,
sm.definition,
sm.uses_ansi_nulls,
sm.uses_quoted_identifier,
sm.is_schema_bound,
sm.execute_as_principal_id
-- using the two system tables sys.sql_modules and sys.objects
FROM sys.sql_modules AS sm
JOIN sys.objects AS o ON sm.object_id = o.object_id
-- from the function 'dbo.ufnGetProductDealerPrice'
WHERE sm.object_id = OBJECT_ID('dbo.fn_constraint')
ORDER BY o.type;
GO
Input:
Output:
object_id object_name type type_desc definition uses_ansi_nulls
uses_quoted_identifier is_schema_bound execute_as_principal_id
Key Learnings:
Status
Description Efforts
(Solved/Not solved)
Completed Date: