Download presentation
Presentation is loading. Please wait.
Published byGrant Gray Modified over 8 years ago
2
Drill Consider the following tables with the following fields: Student: FName, LName, StudentID, Age, Yr, Course Grades: ID, P1, P2, P3 1.Display the first and last name of all freshman 2.Display the ID of anyone who is failing a class. 3.Display the ID of anyone is failing all three classes. 4.Display all fields of all freshmen who are under 15 and all seniors who are over 17. 5.Display all upperclassmen who are in A course whose last name starts with ‘P’ 6.Display all students whose last name starts with S, that are between 15 and 19.
3
Drill Consider the following tables with the following fields: Student: FName, LName, StudentID, Age, Yr, Course Address: StudentID, StreetAddress, City, State, Zip HonorRoll: StudentID, GPA 1.Display the first and last name of all students in the 21200 Zip 2.Display the LastName and GPA of all Seniors on the Honor Roll 3.Display the cities where each student lives. (list each city once) 4.Display (alphabetically) the last names of all underclassmen. 5.Display the min, max, average of GPA, and total number of honor roll students.(use headers: lowest, highest, average, and total) 6.Display the Last Name and GPA of all students who live in ‘Md’. (hint: you need a join with 3 tables)
4
Drill #2 (classwork will be collected) Consider the following tables with the following fields: Student: FName, LName, StudentID, Age, Yr, Course Address: StudentID, StreetAddress, City, State, Zip HonorRoll: StudentID, GPA 1.Display the first and last name of all students who live in Baltimore and are older than 16. 2.Display the LName and GPA of all ‘A’ Course on the Honor Roll w/ a GPA between 3.8 and 4.0 whose last name starts with ‘P’. 3.Display the LName and GPA of all ‘B’ Course students in the 21209 zip (hint: you need a join with 3 tables)
5
Classwork Create a table called CLASS with the fields: ClassName Not Null Size (Number) Null Teacher (Max 20) Not Null Department (Max 20) Not Null Course (‘A’ or ‘B’) Null
6
Joins
10
Keys: Primary Key
11
Keys: Foreign Key
12
Joins
14
Dot Notation Use dot notation when performing a join between two tables with the same column names.
15
Classwork Consider the following tables with the following fields: Student: FName, LName, StudentID, Age, Yr, Course Grades: StudentID, P1, P2, P3 1.Display the full name of all freshman who are failing first period. 2.Display the grades of any student whose name starts with ‘S’.
16
Distinct
19
DISTINCT and ORDER BY SELECT DISTINCT [field],.. [field] FROM [table1], [table2] WHERE [condition],.., [condition] ORDER BY [field],.., [field] This will only return unique values for the “DISTINCT”
20
What does this query do?
22
SELECT DISTINCT [Field] alias,.. [Field] FROM [Table1] alias, [Table2] alias WHERE [condition] IN {SELECT … } ORDER BY [Field],.. [Field]
23
SUM, AVG, MIN, MAX, COUNT
24
SUM, AVG
25
MIN
26
COUNT(*)
27
CREATE Table
28
CREATE TABLE Tablename ( Field1 datatype [not null OR null],.. Fieldn);
29
DataTypes
30
ALTER TABLE
31
ALTER TABLE ADD ALTER TABLE ADD (field datatype);
32
INSERT
33
INSERT INTO …VALUES INSERT INTO [table] VALUES (field1, field2…);
34
DELETE
35
UPDATE/SET
36
GROUP BY Use the GROUP BY Function with Agregate functions (SUM, MIN, MAX, AVG, COUNT) What do you think this query does?
37
GROUP BY/ HAVING To put conditions on a GROUP BY use the HAVING
38
Subqueries A subquery is a query within a query. They are general used in the WHERE (condition) statement. SELECT LName FROM Student WHERE StudentID IN (SELECT StudentID FROM HonorRoll);
39
What does the following SQL statement do?
41
Entity Relationship Model
42
SQL so far SELECTDISTINCT, Alias, dot notation FROM Table Alias, (Joins) WHERE IN, IN (SELECT …), BETWEEN AND, Field <> != >= <= Functions: Min(), Max(), Sum(), Avg(), Count(*) Tables: Create, Alter, Insert, Delete, Update
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.