Intermediate SQL
Relational Languages
用户只需要指出他们想要的答案,不需要指出是如何计算的,DBMS 负责高效的查询。
高端系统有一个复杂的查询优化器 query optimizer,可以重写查询并搜索最佳执行策略。
- Data Manipulation Language
- Data Definition Language
- Data Control Language
Example Database
- student (sid, name, login, age, gpa)
- course (cid, name)
- enrolled (sid, cid, grade)
Join
Aggregate
The GROUP BY
will turn
e.sid | s.sid | S.gpa | e.cid |
---|---|---|---|
53435 | 53435 | 2.25 | 15-721 |
53439 | 53439 | 2.70 | 15-721 |
56023 | 56023 | 2.75 | 15-826 |
59439 | 59439 | 3.90 | 15-826 |
53961 | 53961 | 3.50 | 15-826 |
58345 | 58345 | 1.89 | 15-445 |
into
AVG(s.gpa) | e.cid |
---|---|
2.46 | 15-721 |
3.39 | 15-826 |
1.89 | 15-445 |
String Operations
SQL standard says to use ||
operator to concatenate two or more strings together.