SQL part1) select
select
その結果、ユーザーが表示したいプロパティのリストが表示されます.
distinctキーを使用すると
お寺
tupleが満たさなければならない条件を明確にする
お寺から
クエリーに関連するテーブルのリスト
実行順序
join
joinは、共通カラムを持つtuple間で新しいテーブルを作成します.
内部接続はOを繰り返しXを繰り返すことを許可する
|
ex)
// natrual join. 7개
Select * __from professor natural join teaches__; // inner(=default) join. 8개
Select * __from professor, teches__ where professor.pID = teches.pID;
(inner) join
Select name, cId // 3. 이름과 cID 검색
from professor, teaches // 1. 중간테이블 만들어짐
where professor.pId=teaches.pID; // 2. 둘의 pID가 같은 튜플 중
Select title, name // 3. title, name만 추출
from teaches, course, professor // 1. 이 테이블들의 카티시안곱 테이블 만들어낸 다음
where teches.cID=course.cId and teches.pID=professor.pID and course.deptName='CS'; // 2. 조건들 만족시키는 튜플 들 중
natural join
表にナチュラル結合を適用する場合は、同名のプロパティによって望ましくない結合演算が発生しないように注意してください.
例)
// 잘못된 ver
Select name, title
from professor natural join teches natural join course;
// 올바른 ver1
Select name, title
from professor natural join teaches, course // prof<-> teaches는 Natural join 하고 그 뒤 course는 일반 조인
where teaches.cID = course.cID;
// 올바른 ver2
Select name, title
from (professor natural join teaches) join course using(cID);
// 올바른 ver3
Select name,title
from teaches, course, professor
where dteaches.cID=course.cID and teaches.pID=professor.pID;
Rename "as"
文字列比較演算
like演算子+パターン(%,など)
order by
order byを使用して他のテーブルを作成するのではなく、結果テーブルに入るtupleの順序を変更します.
between
Select name from professor where salary between 5000 and 6000;```
チュートリアルの比較
ex)
Select name, cID
from professor, teaches
where (professor.pID, deptName) = (teaches.pID, 'CS') // 튜플 비교
中伏
SQLはtuple反復を許可する(i.e.multiset)
しゅうごうえんざん
SQLは集約演算もサポート
Null
値が存在する場合、値が存在するかどうか、または値が存在するかどうかなどは不明です.
Exercises
Select name, deptName
from student
where GPA < 2.0;
select distinct name
from student, course, takes
where takes.cID=teaches.cID and teaches.cID='CS' and student.sID=takes.sID and student.cID=teaches.cID;
select distinct name
from student, (course natural join takes) using (sID)
where course.deptName='CS'
where
Select name, salary, department.deptName
from professor, department
where department.chairman=professor.pID
// wrong ver
Select name, salary, department.deptName
from department, professor
where department.deptName = professor.deptName;
次の2番目のエラーverは、わけのわからない「教授が所属する学科」を探している.ただ、教授.deptName属性値には空の値が存在し、空の値を持つturpleは結果関係に結合されません.したがって、2番目のクエリは次のクエリと同じです.
Select name, salary, deptName
from professor
where deptName is not null;
select name
from student
order by GPA desc;
Reference
この問題について(SQL part1) select), 我々は、より多くの情報をここで見つけました https://velog.io/@yesterdaykite/SQL-part1-selectテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol