0% found this document useful (0 votes)
39 views

Dbms Lab Task9

The document contains 5 sections with SQL queries to retrieve aggregate functions like MAX, MIN, COUNT, SUM, and AVG from a teacher table. The MAX section examples find the maximum salary, bonus, years of experience, house allowance, and salary within certain age ranges. The MIN section finds the minimum values for the same fields. COUNT examples return total distinct values and counts where clauses are met. SUM returns total values. AVG returns average values for the same fields.

Uploaded by

Laiba Hafeez
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Dbms Lab Task9

The document contains 5 sections with SQL queries to retrieve aggregate functions like MAX, MIN, COUNT, SUM, and AVG from a teacher table. The MAX section examples find the maximum salary, bonus, years of experience, house allowance, and salary within certain age ranges. The MIN section finds the minimum values for the same fields. COUNT examples return total distinct values and counts where clauses are met. SUM returns total values. AVG returns average values for the same fields.

Uploaded by

Laiba Hafeez
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Tasks 9

1.Max
----Query 1: retrieve max salary from Teacher.
select Max(salary) as[Maximum sallary] from teacher
--Query 2: retrieve max Bonus from teacher where t_fname starts with S.
select Max(bonus) as[Maximum Bonus] from teacher where t_fname like 's%'
----Query 3: retrieve max yearsofexp from Teachers where age is in 30 and
35.year
select Max(yearofexp) as[Maximum yearofexp] from teacher where age in(30,35)
---Query 4: retrieve max house allowance from teacher where qualification is MS
select Max(houseallowence) as[Maximum houseallowence] from teacher where
qualification='Ms'
---Query 5: retrieve max salary where age is greater than 25 and less than 30.
select Max(salary) as[Maximum salary] from teacher where age>25 AND age<30

2.MIN
---Query 1: retrieve min salary from Teacher.
select Min(salary) as[Minimum sallary] from teacher
--Query 2: retrieve min Bonus from teacher where t_fname starts with S.
select Min(bonus) as[Minimum Bonus] from teacher where t_fname like 's%'
--Query 3: retrieve min yearsofexp from Teachers where age is in 30 and 35.
select Min(yearofexp) as[Minimum yearofexp] from teacher where age in(30,35)
--Query 4: retrieve min house allowance from teacher where qualification is MS
select Min(houseallowence) as[Minimum houseallowence] from teacher where
qualification='Ms'
--Query 5: retrieve min salary where age is greater than 25 and less than 30.
select Min(salary) as[Minimum salary] from teacher where age>25 AND age<30

3.Count
--Query 1: retrieve total number of distinct yearsofexp from teacher.
select count(distinct yearofexp) as[Total yearsofexp] from teacher
--Query 2: retrieve total number of salaries whose qualification is MS.
select count(salary) as [Total sallaries] from teacher where qualification='Ms'
--Query 3: retrieve total number of distinct t_name from teacher.
select count(distinct t_fname+' '+t_lname) as [Total Teachers distinct name]
from teacher
--Query 4: retrieve total number of salaries from teacher where age is greater
than 28.
select count(salary) as[Total sallaries] from teacher where age>28
--Query 5: retrieve total number of distinct qualifications from teacher
select count(distinct qualification) as[Total distinct qualifications] from
teacher
4.Sum

--Query 1: show total salary from teachers.


select sum(salary) as [Total sallaries] from teacher
--Query 2: retrieve total years of experience from teachers.
select sum(yearofexp) as [Total yearsofexp] from teacher
-- Query 3: retrieve total Bonus from Teacher where tid is 5001 and 5007.
select sum(bonus) as [Total bonus] from teacher where tid='5001' Or tid='5007'
--Query 4: retrieve total House Allowance where age is greater than 30.
select sum(houseallowence) as [Total houseallowence] from teacher where age>30
--Query 5: retrieve sum of all bonus where t_lname is Ahmad
select sum(bonus) as [Total bonus] from teacher where t_lname='Ahmad'

5.Bonus
--Query 1: show Average salary from teachers.
select Avg (salary) as[Avg sallary] from teacher
--Query 2: retrieve Average years of experience from teachers.
select Avg (yearofexp) as[Avg yearsofexp] from teacher
--Query 3: retrieve Average Bonus from Teacher where tid is 5001 and 5007.
select Avg (bonus) as[Avg bonus] from teacher where tid=5001 or tid=5007
--Query 4: retrieve Average House Allowance where age is greater than 30.
select Avg (houseallowence) as[Avg houseallowence] from teacher where age>30
--Query 5: retrieve Average of all bonus where t_lname is Ahmad
select Avg (bonus) as[Avg bonus] from teacher where t_lname='Ahmad'

Exercise9

You might also like