0% found this document useful (0 votes)
14 views3 pages

Mis Homework 4

mis

Uploaded by

aydanabbasova2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Mis Homework 4

mis

Uploaded by

aydanabbasova2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Aydan Abbasova

Management Information System CRN: 20338


Homework 4

#Question 1-List all student related inofrmation if second letter of


student's last name is O.
#Hint -you may need to use both % and _
txt='''
Select *
From Student
Where StdLastName LIKE '_O%'
'''
Q1 = psql.sqldf(txt)
Q1

#Question 2-List City names where Student or Faculty live. Name the column
AS City.
txt='''
Select StdCity AS City
From Student
UNION
Select FacCity AS City
From Faculty
'''
Q2 = psql.sqldf(txt)
Q2

#Question 3-List City names where both Student and Faculty live in .
txt='''
Select StdCity AS City
From Student
INTERSECT
Select FacCity AS City
From Faculty
'''
Q3 = psql.sqldf(txt)
Q3

#Question 4-List City names where Student lives but Faculty does not
live in .
txt='''
Select StdCity AS City
From Student
EXCEPT
Select FacCity AS City
From Faculty
'''
Q4 = psql.sqldf(txt)
Q4

#Question 5-List City names where Faculty lives but Student does not live
in .
txt='''
Select FacCity AS City
From Faculty
EXCEPT
Select StdCity AS City
From Student
'''
Q5 = psql.sqldf(txt)
Q5

#Question 6-What is the mininimum, maximum and average GPA of Student?


#How many students are there in student table?
txt='''
Select Min(StdGPA) AS MinStdGPA, Max(StdGPA) AS MaxStdGPA, Avg(StdGPA) AS
AvgStdGPA, count(*) AS 'NoofStudents'
From Student
'''
Q6 = psql.sqldf(txt)
Q6

#Question 7-Summarize minimum and maximium and average GPA of student by


StdClass.
#How many student are there in each class?
txt='''
Select StdClass, Min(StdGPA) AS MinStdGPA, Max(StdGPA) AS MaxStdGPA,
Avg(StdGPA) AS AvgStdGPA, count(*) AS 'NoofStudents'
From Student
Group by StdClass

'''
Q7 = psql.sqldf(txt)
Q7

#Question 8-List the average StdGPA of student based on StdCity.


#how many students lives in each city. Order the city names in descending
order.
txt='''
Select StdCity, Avg(StdGPA), count(*) AS 'NoofStudents'
From Student
Group by StdCity
Order by StdCity DESC
'''
Q8 = psql.sqldf(txt)
Q8

#Query 9-List the average StdGPA of student based on StdCity if there


#are more than 1 student lives in the city .Order the city names in
ascending order.
#Hint: you will use group by and having
txt='''
Select StdCity, Avg(StdGPA), count(*)
From Student
Group by StdCity
Having count(*)>1
'''
Q9= psql.sqldf(txt)
Q9

#Query 10-How many faculty membes are there in each department?


#Calculate the the average salary of faculty in each department?
txt='''
Select FacDept, count(*) AS 'NoofFaculty', Avg(FacSalary) AS
'AvgSalaryForDept'
From Faculty
Group by FacDept
'''
Q10 = psql.sqldf(txt)
Q10

##Query 11-Get All student related information of student with lowest GPA.
txt='''
Select *
From Student
Order by StdGPA ASC
Limit 1 Offset 0
'''
Q11 = psql.sqldf(txt)
Q11

You might also like