Skip to content

Commit

Permalink
Merge pull request #1 from ichn-hu/master
Browse files Browse the repository at this point in the history
merge ass2 into branch
  • Loading branch information
xiaoas authored Mar 23, 2020
2 parents eaf671f + 58193a6 commit 906e0e9
Show file tree
Hide file tree
Showing 317 changed files with 2,524 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docs/
docs/
21 changes: 21 additions & 0 deletions assignments/ass1/create_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CREATE TABLE employee (
id INT PRIMARY KEY,
name VARCHAR(32),
office VARCHAR(32),
age INT
);

CREATE TABLE book (
id INT PRIMARY KEY,
name VARCHAR(32),
author VARCHAR(32),
publisher VARCHAR(32)
);

CREATE TABLE record (
book_id INT,
employee_id INT,
time DATE,
FOREIGN KEY (book_id) REFERENCES book(id),
FOREIGN KEY (employee_id) REFERENCES employee(id)
);
3 changes: 3 additions & 0 deletions assignments/ass1/submission/15307130201/1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT *
FROM employee
WHERE name = 'Jones';
3 changes: 3 additions & 0 deletions assignments/ass1/submission/15307130201/2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT name
FROM employee
WHERE id = 1 OR id = 2;
4 changes: 4 additions & 0 deletions assignments/ass1/submission/15307130201/3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT name
FROM employee
WHERE id != 1
ORDER BY id;
4 changes: 4 additions & 0 deletions assignments/ass1/submission/15307130201/4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT name
FROM employee
WHERE age >= 25 and age <= 30
ORDER BY id;
4 changes: 4 additions & 0 deletions assignments/ass1/submission/15307130201/5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT *
FROM employee
WHERE name LIKE 'J%'
ORDER BY age;
3 changes: 3 additions & 0 deletions assignments/ass1/submission/15307130201/6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT DISTINCT publisher
FROM book
ORDER BY publisher;
4 changes: 4 additions & 0 deletions assignments/ass1/submission/15307130201/7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT DISTINCT book_id
FROM record
WHERE time >= '2016-10-31'
ORDER BY book_id;
6 changes: 6 additions & 0 deletions assignments/ass1/submission/15307130201/8.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT e.id, e.name, COUNT(*) as num
FROM employee AS e, record
WHERE e.id = record.employee_id
GROUP BY e.id
HAVING num > 1
ORDER BY num DESC;
21 changes: 21 additions & 0 deletions assignments/ass1/submission/15307130201/create_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CREATE TABLE employee (
id INT(16),
name VARCHAR(32),
office VARCHAR(32),
age INT(8),
PRIMARY KEY (id)
);
CREATE TABLE book (
id INT(16),
name VARCHAR(32),
author VARCHAR(32),
publisher VARCHAR(32),
PRIMARY KEY (id)
);
CREATE TABLE record (
book_id INT(16),
employee_id INT(16),
time DATE,
FOREIGN KEY (book_id) REFERENCES book (id),
FOREIGN KEY (employee_id) REFERENCES employee (id)
);
3 changes: 3 additions & 0 deletions assignments/ass1/submission/18300200009/1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT *
FROM employee
WHERE name='Jones';
3 changes: 3 additions & 0 deletions assignments/ass1/submission/18300200009/2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT name
FROM employee
WHERE id=1 OR id=2;
4 changes: 4 additions & 0 deletions assignments/ass1/submission/18300200009/3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT name
FROM employee
WHERE id!=1
ORDER BY id;
4 changes: 4 additions & 0 deletions assignments/ass1/submission/18300200009/4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT name
FROM employee
WHERE age>=25 AND age<=30
ORDER BY id;
4 changes: 4 additions & 0 deletions assignments/ass1/submission/18300200009/5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT *
FROM employee
WHERE name LIKE 'J%'
ORDER BY age;
3 changes: 3 additions & 0 deletions assignments/ass1/submission/18300200009/6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT DISTINCT publisher
FROM book
ORDER BY publisher;
4 changes: 4 additions & 0 deletions assignments/ass1/submission/18300200009/7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT DISTINCT book_id
FROM record
WHERE time > 2016-10-31
ORDER BY book_id;
6 changes: 6 additions & 0 deletions assignments/ass1/submission/18300200009/8.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT id,name,count(book_id) AS num
FROM record,employee
WHERE id=employee_id
GROUP BY id
HAVING count(book_id)>1
ORDER BY num;
25 changes: 25 additions & 0 deletions assignments/ass1/submission/18300200009/create_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
CREATE TABLE employee(
id INT NOT NULL,
name VARCHAR(32),
office VARCHAR(32),
age INT,
PRIMARY KEY(id),
CHECK (id>=0 AND id<=100)
);
CREATE TABLE book(
id INT NOT NULL,
name VARCHAR(32),
author VARCHAR(32),
publisher VARCHAR(32),
PRIMARY KEY(id)
);
CREATE TABLE record(
book_id INT NOT NULL,
employee_id INT NOT NULL,
time DATE,
FOREIGN KEY (book_id) REFERENCES book(id),
FOREIGN KEY (employee_id) REFERENCES employee(id)
);



3 changes: 3 additions & 0 deletions assignments/ass1/submission/18300200012/1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT *
FROM employee
WHERE name="Jones";
3 changes: 3 additions & 0 deletions assignments/ass1/submission/18300200012/2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT name
FROM employee
WHERE id=1 or id = 2;
4 changes: 4 additions & 0 deletions assignments/ass1/submission/18300200012/3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT name
FROM employee
WHERE id!=1
ORDER BY id;
4 changes: 4 additions & 0 deletions assignments/ass1/submission/18300200012/4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT name
FROM employee
WHERE age BETWEEN 25 AND 30
ORDER BY id;
4 changes: 4 additions & 0 deletions assignments/ass1/submission/18300200012/5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT *
FROM employee
WHERE name LIKE "J%"
ORDER BY age;
5 changes: 5 additions & 0 deletions assignments/ass1/submission/18300200012/6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT publisher
FROM book
GROUP BY publisher
HAVING count(id)>2
ORDER BY publisher ;
4 changes: 4 additions & 0 deletions assignments/ass1/submission/18300200012/7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT DISTINCT book_id AS id
FROM record
WHERE time > '2016-10-31'
ORDER BY book_id;
5 changes: 5 additions & 0 deletions assignments/ass1/submission/18300200012/8.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT id,name,count(id) AS num
FROM employee JOIN record ON id = employee_id
GROUP BY id,name
HAVING num>1
ORDER BY num DESC
27 changes: 27 additions & 0 deletions assignments/ass1/submission/18300200012/create_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CREATE TABLE employee
(
id INT NOT NULL,
name VARCHAR(32),
office VARCHAR(32),
age INT,
check (age <= 100 and age >= 0),
PRIMARY KEY (id)
);

CREATE TABLE book
(
id INT NOT NULL,
name VARCHAR(32),
author VARCHAR(32),
publisher VARCHAR(32),
PRIMARY KEY (id)
);

CREATE TABLE record
(
book_id INT,
employee_id INT,
time DATE,
FOREIGN KEY(book_id) references book(id),
FOREIGN KEY(employee_id) references employee(id)
);
3 changes: 3 additions & 0 deletions assignments/ass1/submission/18300200015/1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select *
from employee
where name='Jones';
3 changes: 3 additions & 0 deletions assignments/ass1/submission/18300200015/2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name
from employee
where id='1' or id='2';
4 changes: 4 additions & 0 deletions assignments/ass1/submission/18300200015/3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
select name
from employee
where id!='1'
order by id;
4 changes: 4 additions & 0 deletions assignments/ass1/submission/18300200015/4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
select name
from employee
where age>=25 and age<=30
order by id;
4 changes: 4 additions & 0 deletions assignments/ass1/submission/18300200015/5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
select *
from employee
where name like 'J%'
order by age;
4 changes: 4 additions & 0 deletions assignments/ass1/submission/18300200015/6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
select distinct x.publisher
from book as x,book as y
where x.publisher=y.publisher and x.name!=y.name
order by publisher;
4 changes: 4 additions & 0 deletions assignments/ass1/submission/18300200015/7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
select book_id
from record
where time>'2016-10-31'
order by book_id;
6 changes: 6 additions & 0 deletions assignments/ass1/submission/18300200015/8.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
select employee.id,employee.name,count(record.employee_id)
from record,employee
where record.employee_id=employee.id
group by employee.id
having count(record.employee_id)>=2
order by count(record.employee_id) desc;
23 changes: 23 additions & 0 deletions assignments/ass1/submission/18300200015/create_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
create table employee(
id int,
name varchar(32),
office varchar(32),
age smallint,
primary key(id)
);

create table book(
id int,
name varchar(32),
author varchar(32),
publisher varchar(32),
primary key(id)
);

create table record(
book_id int,
employee_id int,
time date,
foreign key(book_id)references book(id),
foreign key(employee_id)references employee(id)
);
1 change: 1 addition & 0 deletions assignments/ass1/submission/18300750006/1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * FROM employee WHERE name="Jones" ;
1 change: 1 addition & 0 deletions assignments/ass1/submission/18300750006/2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT name FROM employee WHERE id = 1 OR id = 2 ;
1 change: 1 addition & 0 deletions assignments/ass1/submission/18300750006/3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT name FROM employee WHERE id != 1 ORDER BY id;
1 change: 1 addition & 0 deletions assignments/ass1/submission/18300750006/4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT name FROM employee WHERE age <= 30 AND age >= 25 ORDER BY id ;
1 change: 1 addition & 0 deletions assignments/ass1/submission/18300750006/5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * FROM employee WHERE name LIKE "J%" ORDER BY age ;
2 changes: 2 additions & 0 deletions assignments/ass1/submission/18300750006/6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT DISTINCT X.publisher FROM book AS X , book AS Y
WHERE X.name != Y.name AND X.publisher = Y.publisher ORDER BY publisher;
2 changes: 2 additions & 0 deletions assignments/ass1/submission/18300750006/7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT DISTINCT book_id FROM record
WHERE time > "2016-10-31" ORDER BY book_id ;
6 changes: 6 additions & 0 deletions assignments/ass1/submission/18300750006/8.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT employee.id, employee.name, COUNT(record.employee_id)
AS num FROM (employee INNER JOIN record
ON employee.id = record.employee_id )
GROUP BY employee.id
HAVING COUNT(record.employee_id) >=2
ORDER BY COUNT(record.employee_id) DESC;
18 changes: 18 additions & 0 deletions assignments/ass1/submission/18300750006/create_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CREATE TABLE employee
( id VARCHAR(32) NOT NULL PRIMARY KEY,
name CHAR(32) NOT NULL,
office CHAR(32) NOT NULL,
age INT NOT NULL CHECK(age >= 0 AND age <= 100));

CREATE TABLE book
( id VARCHAR(32) NOT NULL PRIMARY KEY,
name CHAR(32) NOT NULL,
author CHAR(32) NOT NULL,
publisher CHAR(32) NOT NULL);

CREATE TABLE record
( book_id VARCHAR(32) NOT NULL,
employee_id CHAR(32) NOT NULL,
time DATE NOT NULL,
FOREIGN KEY (book_id) REFERENCES book(id),
FOREIGN KEY (employee_id) REFERENCES employee(id));
7 changes: 7 additions & 0 deletions assignments/ass1/submission/18307130003/1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Query all fields for employees named Jones
SELECT
*
FROM
employee
WHERE
name = 'Jones';
7 changes: 7 additions & 0 deletions assignments/ass1/submission/18307130003/2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Query the name of employees with ID equals to 1 or 2 (order does not matter)
SELECT
name
FROM
employee
WHERE
id IN (1, 2);
9 changes: 9 additions & 0 deletions assignments/ass1/submission/18307130003/3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Query the name of all employees except the one whose ID is 1 (ordered by ID)
SELECT
name
FROM
employee
WHERE
id <> 1
ORDER BY
id;
10 changes: 10 additions & 0 deletions assignments/ass1/submission/18307130003/4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Query the name of all employees with age between 25 and 30 (inclusively,
-- ordered by ID)
SELECT
name
FROM
employee
WHERE
age BETWEEN 25 AND 30
ORDER BY
id;
Loading

0 comments on commit 906e0e9

Please sign in to comment.