/notes/code/sql/HW_Department.sql (30643f225360335dba1f1de310c48a070cb8084e) (2171 bytes) (mode 100644) (type blob)
/*
Preamble:
The following is in case you want to run your program on your installation:
*/
DROP SCHEMA IF EXISTS HW_Department;
-- Carefull, we are dropping the schema HW_Department if it
-- exists already, and all the data in it.
CREATE SCHEMA HW_Department;
-- And then re-creating it.
USE HW_Department;
/*
End of the preamble.
*/
-- start snippet statement
/* code/sql/HW_Department.sql */
CREATE TABLE DEPARTMENT (
ID INT PRIMARY KEY,
NAME VARCHAR(30)
);
CREATE TABLE EMPLOYEE (
ID INT PRIMARY KEY,
NAME VARCHAR(30),
Hired DATE,
Department INT,
FOREIGN KEY (Department) REFERENCES DEPARTMENT (ID)
);
INSERT INTO DEPARTMENT
VALUES (
1,
"Storage"),
(
2,
"Hardware");
INSERT INTO EMPLOYEE
VALUES (
1,
"Bob",
20100101,
1),
(
2,
"Samantha",
20150101,
1),
(
3,
"Mark",
20050101,
2),
(
4,
"Karen",
NULL,
1),
(
5,
"Jocelyn",
20100101,
1);
-- end snippet statement
/*
*
*
* Below are the solution, but think about it first!
*
*
*
*/
-- start snippet solution1
SELECT EMPLOYEE.Name
FROM EMPLOYEE,
DEPARTMENT
WHERE DEPARTMENT.Name = "Storage"
AND EMPLOYEE.Department = DEPARTMENT.ID;
-- end snippet solution1
/*
Will return:
Bob
Samantha
Karen
Jocelyn
and not Mark, since that employee works in a differente department.
*/
-- start snippet solution2
SELECT Name
FROM EMPLOYEE
WHERE Hired <= ALL (
SELECT Hired
FROM EMPLOYEE
WHERE Hired IS NOT NULL);
-- end snippet solution2
/*
Will return
Mark
since he has the smallest hiring date,
excluding Karen (whose hiring date is
unknown).
*/
-- start snippet solution3
SELECT EMPLOYEE.Name
FROM EMPLOYEE,
DEPARTMENT
WHERE Hired <= ALL (
SELECT Hired
FROM EMPLOYEE
WHERE Hired IS NOT NULL
AND DEPARTMENT.Name = "Storage"
AND EMPLOYEE.Department = DEPARTMENT.ID)
AND DEPARTMENT.Name = "Storage"
AND EMPLOYEE.Department = DEPARTMENT.ID;
-- end snippet solution3
/*
Will return
Bob
Jocelyn
since those are the two employees of the
department whose name is Storage that have
the smallest hiring date among the
employee of the department whose name is storage.
*/
Mode |
Type |
Size |
Ref |
File |
100644 |
blob |
15398 |
ee75155d2d99639acd17d31b2cc23cd752078e7e |
CONTRIB.md |
100644 |
blob |
20625 |
25b8e45e7f103089fb70fae5a219f09a29ef5312 |
KNOWN_BUGS.md |
100644 |
blob |
17217 |
e5c1f9f898cca948da42333b100e331d62b61d3c |
LICENSE.md |
100644 |
blob |
1997 |
f8801648fd4ba5843a2cbca8b10e4f69ba5d9b25 |
Makefile |
100644 |
blob |
6695 |
0b91924ffc7b73e2d36150369d4fd41a44b099c5 |
README.md |
040000 |
tree |
- |
eb7afc38251ada69e1967e1ce3e49967eca2267c |
install |
040000 |
tree |
- |
f16b283429b64b620b3bd7681a446ff54d504f84 |
notes |
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/caubert/CSCI_3410
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/caubert/CSCI_3410
Clone this repository using git:
git clone git://git.rocketgit.com/user/caubert/CSCI_3410
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main