Assignment 1
Basic SQL
插入语法 (INSRT INTO)
1 | INSERT INTO table_name ( field1, field2,...fieldN ) |
读取数据表
1 | select * from runoob_tbl; |
Execrises
P1
P2
Solution
p1
p2
p3
p4
p5
p6
Lab2 (ttl)
PART1: Simple queries
1 | -- Average grade |
- Simple joins:
1 | -- 1.What lecturers have taught you? - sort by their birthday |
Unions:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22-- What names (of students, lecturers or courses) exists?
SELECT name
FROM Courses
UNION
SELECT first_name
FROM Students
UNION
SELECT last_name
FROM Students
UNION
SELECT first_name
FROM Lecturers
UNION
SELECT last_name
FROM Lecturers;
-- List all lecturers and studnets, ordered by their first and last name
SELECT first_name, last_name
FROM Students
UNION
SELECT first_name,last_name
FROM Lecturers
ORDER BY first_name, last_name;How would you do the above simple queries for each student or each course, depending(instead of you and COMP207)If you got the point of GROUP BY, this is hopefully reasonably clear and easy to do, otherwise you will hopefully get it from the answer… How about the simple joins?
1 | -- Simple queries: |
PART 2: More complex queries
1 | -- Find the students you have shared a course with |