I have IT homework that is due at midnight tonight. For our assignment, we had to create a table in an SQL database off my school AFS database. I am using MobaXTerm to do this homework assignment.
I created a table name "student". I created the entire table correctly. It is correct, because my professor gave me the exact command to create it. Here are the columns in order: id, firstname, lastname, address, state, gpa, credits. I populated this table with 20 students, however I do not want to post the picture of the result on here, because it has personal info on it.
I answered the other questions correctly, however I am stuck on this question that has multiple questions in it:
Next, write and run (issue) SQL queries that do the following. For each query, provide screenshots for the SQL query and the results within a Word document so I can grade it.
a. Show state and gpa information about students with the first name Peter (I was told to add students with the name "Peter" before I created this table).
This one is correct here is the command i used:
select state, gpa, firstname from student where lastname = 'Peter';
b. Retrieve the last names, state, and credits of all students that are NOT from AZ or FL. Order by the state.
I am struggling on this one, because I do not know how to show the table of students that are both NOT from AZ and FL.
But here is a command that worked to show if they are not from one state.
select, lastname, credits, state from student where state != 'AZ'
How am I supposed to write that student is not equal to both AZ and FL?
c. How many students live on '10 Main Street'?
select id, address from student where address='10 Main Street';
This question is correct.
d. Retrieve all sophomore student ids along with their credits that are NOT C students (see the table for definition for “sophomore” and “C” grades).
So the table shows that a sophomore has 33-64 credits. A C student has a GPA of 1.7-2.69. So what is my line of command to show these range of numbers?
Q: How am I supposed to write that student is not equal to both AZ and FL?
... WHERE state != 'AZ' AND state != 'FL'
Q: How many students ...
SELECT COUNT(*) AS count_students FROM ...
Q: Sophmore not C
... WHERE credits >= 33 AND credits <= 64
AND NOT ( gpa >= 1.7 AND gpa <= 2.69)
Related
I've been tasked to create a student database for my work at a College.
The database will be used for calculating a students marks. This will involve adding a students name and ID, then adding the modules they will take and finally entering the marks for each module.
I've created the tables, query and form so far to show the students modules however I'm really struggling on the last part on how to enter marks for the module.
One of the main problems is also the weighting of each mark as some modules have 1, 2 or 3 components: e.g. Coursework 50% Exam 50% so I will have to also incorporate this into the module marks.
So far I've created 3 tables:
StudentInfo -
StudentID,
FirstName,
LastName
Modules
ModuleID,
ModuleTitle,
CourseCode,
Component1,
Weight1,
Component2,
Weight2,
Component3,
Weight3
Enrolment -
ID
StudentID
ModuleID
I've created a Query which includes:
StudentID,
ModuleID,
FirstName,
LastName,
ModuleTitle
And also a Form from the StudentInfo table with a Subform of the Enrolment table.
I'm a beginner in Access to any help or advice would be much appreciated!
Happy to email the database if someone does want to have a look/make changes.
Many thanks,
Sarah
You've done most of the hard work already, you just need another table to hold the marks. There are plenty of different ways you could structure this, but as an example, you could copy the design from your Enrolment table and extend it to include marks for each component.
It might look something like this:
Marks - ID, StudentID, ModuleID, Component1Mark, Component2Mark, Component3Mark
Then to get your weighted results for ModuleID X (assuming a 30% weighting is entered as 0.3) you would query it like:
select marks.StudentID, (module.Weight1 * marks.Component1Mark) +
(module.Weight2 * marks.Component2Mark) + (module.Weight3 * marks.Component3Mark)
from module
inner join marks on module.ModuleID = marks.ModuleID
where module.ModuleID = X
I know this is somewhat of a specialized question since only a small percentage of members will even have heard of PowerSchool, but it's hard to find help for this. Given a start date and end date, I need to run a query that will return the student ID's for all students who were enrolled in the District during that time period. If I could use that with 'WITH AS', I could add it to an attendance query 'Where' clause like below. This is what I've got so far, but I don't know how to check it's accuracy:
SELECT * FROM Students
WHERE ID IN (
SELECT studentid FROM ps_adaadm_defaults_all
WHERE schoolid IN ('16', '28', '40')
AND calendardate >= '1-May-15'
AND calendardate <= '31-May-15'
GROUP BY studentid)
ORDER BY LastFirst;
"ps_adaadm_defaults_all" is a PowerSchool View that is mainly for ADM so my assumption here is that if a student ID exists in ps_adaadm_defaults_all with a date between the two given dates, that student was enrolled at least that day regardless of attendance, correct? Any PowerSchool users out there that can lend a hand?
I get results with this query but when I try to verify the accuracy by using the PowerSchool site, the results aren't exactly the same. What I mean by using the site is I log in as district admin, set Term to 15-16 year, School to desired school and select students whose last names begin with 'A'. I then start comparing the list it provides with the students from the query results whose last names begin with 'A'. I am noticing though that there are names that I get with my query that are not showing on the site and I think it's due to their exitdate being prior to the current schoolyear. Those students were obviously enrolled at that time, but their names aren't in the PowerSchool results. I'm thinking because they're not enrolled anymore? Is there any way for me to test the accuracy of this query? Am I even on the right track? Thanks in advance.
It sounds to me like you have two questions:
What is the best query to return all students who were enrolled during a given time period?
What is the best way to check that my query is selecting all records it should be?
I'd use the ps_enrollment view for your query. It includes student id, school id, and start and end dates, so it can be used to find all students who were enrolled at a certain point in time.
Students enrolled for the whole specified time period
SELECT UNIQUE pe.StudentID
FROM ps_enrollment pe
WHERE pe.schoolid IN ('16', '28', '40')
AND pe.EntryDate <= '05/01/2015'
AND pe.ExitDate >= '05/30/2015'
Students enrolled at any time within the specified time period
SELECT UNIQUE pe.StudentID
FROM ps_enrollment pe
WHERE pe.schoolid IN ('16', '28', '40')
AND (
(pe.EntryDate <= '05/01/2015' AND pe.ExitDate >= '05/01/2015')
OR (pe.EntryDate <= '05/30/2015' AND pe.ExitDate >= '05/30/2015')
OR (pe.EntryDate >= '05/01/2015' AND pe.ExitDate <= '05/30/2015')
)
In the above example, the three conditions inside the AND check for enrollments that either started before or on and ended after or on the first date, then the second date, and finally checks for any enrollments that happened in between the two dates.
Note: I used UNIQUE instead of GROUP BY. I think it fits what you're doing a little bit more.
The easiest way to check these numbers in the admin side is to use System Reports -> Membership and Enrollment -> Enrollment Summary by Date. This is an easy way to check enrolled students numbers at any point in time, and also will give you the list of those specific students. It includes inactive students.
You can double-check that it's working perfectly by entering a single date in your query instead of using a date range, and by checking that date against the Enrollment Summary by Date. When I did this for our district, my query pulled 7 extra records (out of over 7000), but upon investigation, all of those were due to bad reenrollment records, so it appears to be working correctly.
When you search PowerSchool from the admin website, it only returns active students regardless of what term you select. In other words, I can't select "2000-2001" from the terms list and magically have everything reflect that term.
I can think of a couple things that may be affecting your searches:
search by using a forward slash to include inactive students "/lastname"
if you are searching HS students - remember that seniors transfer to a special school when they graduate
A better way to verify your query results would be to use the ADA/ADM section under System Reports. Reduce your query to one date and then run the ADA/ADM by Date report for the same day.
Just came across this and for anyone that is reading through this, PowerSchool has come up with "as of" selections.
Examples:
*as_of=09/30/2020;enroll_status=0
*as_of=09/30/2020;track=D
In my exam we were given the following relations:
COURSES(**Number**, School, CourseName)
STUDENTS(**SNumber**, Surname, FirstName, School)
EXAMS(**Student**, **Course**, Grade, Date)
where the keys are in bold. The EXAMS relation stores information of students that passed an exam for a given course .EXAMS.Student references STUDENTS.SNumber and EXAMS.Course references COURSES.Number.
We wear asked to write one SQL query that retrieves all the following information for each student number:
-their surname
-how many different exams they passed
-how many different grades they obtained
-the minimum, average and maximum grade they obtained in their exams."
Firstly, I included in my answer that I noticed that, as EXAMS only stores information about a student who passed an exam, there is no way to know if a student failed an exam and so we could only count how many different pass grades they obtained. Here is the query I wrote:
SELECT S.SNumber, S.Surame,
COUNT(E.Student) AS NumberOfExamsPassed,
COUNT(DISTINCT E.Grade) AS NumberOfDifferentPassGrades,
MIN(E.Grade) AS MinimumGrade,
MAX(E.Grade) AS MaximumGrade,
AVG(E.Grade) AS AverageGrade
FROM Students S, EXAMS E
GROUP BY E.Student;
Would this be a sufficient solution?
You should use Explicit Joins.
SELECT S.SNumber, S.Surame,
COUNT(E.Student) AS NumberOfExamsPassed,
COUNT(DISTINCT E.Grade) AS NumberOfDifferentPassGrades,
MIN(E.Grade) AS MinimumGrade,
MAX(E.Grade) AS MaximumGrade,
AVG(E.Grade) AS AverageGrade
FROM Students S
INNER JOIN EXAMS E ON S.SNumber = E.Student
GROUP BY E.Student;
I have a MySQL table with around 4 million+ rows. Let us say the table is as follows:
Columns in table Person:
Id
Name
Age
Marital Status
Education Level
'Location Country'
'Description'
When I run a query based on Age, I also want to have a summary count of people with the same age in different marital status and also with different 'Education Level' and 'Location Country'.
When I run a query based on Age and Education Level, I also want to have a summary count of people with the same age and Education Level in different marital status and also with different 'Location Country'.
For example, the query issued would be SELECT * FROM Person WHERE Age = 27;. I also want results that would be produced by SELECT Education Level, COUNT(*) FROM Person WHERE Age = 27 GROUP BY Education Level; and SELECT Location Country, COUNT(*) FROM Person WHERE Age = 27 GROUP BY Location Country;
Also, this becomes more challenging for me when I have to do a search based on keywords on description and want a summary count on each of the other columns. The application I am developing is a sort of search engine. This can be seen in sites like Ebay,
I can possibly run these queries separately. But, with 4 million rows, the GROUP BY query will take substantial amount of time. This is an internet application and the query should complete within few seconds.
Any help would be much appreciated.
You can do both in one query
SELECT p.*, count(p2.id)
FROM Person p, Person p2
WHERE p2.Age = p.age and p2.marital != p.marital and p1.education != p2.education
GROUP BY p1.id
In such situation, I would suggest to save data in a memcache cache. You can expire cache if new data inserted to table or after some expiration time, to avoid long query execution. Another improvement would be using a LIMIT to reduce number of row returned by DB like this:
SELECT p.*, count(p2.id)
FROM Person p, Person p2
WHERE p2.Age = p.age and p2.marital != p.marital and p1.education != p2.education
GROUP BY p1.id
LIMIT 10
From what you are describing, I would have a separate aggregate table to query directly from that has those "roll-up" stats you want. How frequent is the "Person" table getting added to / changed. If you are only storing a person's "Age", what is the basis of the age if no date, and you add the person again in future they would have multiple records... such that
At age X, so many people were married (or not) and had this level of education.
At age Y, so many people... etc..
I would create a summary table, something like
create table AgeStat (
age int,
married int,
single int,
divorced int,
HighSchool int,
Associates int,
Bachelors int,
Masters int,
Doctorate int )
Then, add a trigger to the person table such that during insert (or inclusive of update/delete as needed), the new record just adds 1 to each respective count applicable.
Then, for your web app, it would be instantaneous to grab one record from this summary table where age = 27 and you have ALL your classification stats.
However, if you distinctly wanted to know how many Married with Masters degree, you would have to roll back to master person list.
Alternatively, you could do a similar pre-aggregation but down a level of granularity something like
create table AgeStat (
age int,
maritalstat int, -- but I would actually use an enumerated value for marital status
educationlevel int, -- and education level vs a hard description of each.
peoplecount int )
and likewise have a trigger that updates the count based on the two combination elements per age. Then, if you wanted the total "Married", you can sum(peoplecount) for age = 27 and maritalstat=(enumerator for "married" value)
Good luck, and hope it helps alternative solution for you.
I'm creating a simple database for a school. I currently have 2 forms namely frmStudents and frmGrades. I use grades to refer to grade 1, 2, 3, .., 12 rather than exam grades. The frmGrades contains the fields grade (primary key) and Fees. The frmStudents contains ID (primary key), name, grade, fees etc. The ID is an auto-generated number, name is text, and grade is linked to the field grade in frmGrades.
I'm intending to first use frmGrades to enter all grades and the corresponding fees. Then I'll enter students information into frmStudents choosing one of the grades from the grades list. My problem is how do I autopopulate the fees value based on the chosen grade?
I need to achieve this in VBA but I'm not familiar with the language at all. In psuedocode this is what I'm trying to achieve:
Private Sub frmStudents_Grade_AfterUpdate()
frmStudents.Fees.text = "Select Fees from frmGrades where frmGrades.Grade = frmStudents.Grade"
End Sub
I hope my question is clear. Thanks in advance.
First, do you really want to do this? The fee is already available in Grades, so do you need it in Student? If you do, is it because the fee changes? Also, won't the student have a different fee and grade each year, so you will want a third table:
StudentID
Date
Grade
Fee
However, if your design is really so simple, include the fee as a column in a combo for grades and update the textbox bound to the student fee from the combo column.
Grade combo on student form
Row Source: SELECT Grade, Fee FROM Grades ORDER BY Grade
Bound Column : 1
Column Count : 2
Column Widthes: 2,0
After update
Me.txtFee = Me.cboGrade.Column(1)