commiting before merge conflicts
This commit is contained in:
1
cst363/.gitignore
vendored
1
cst363/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
lab/
|
||||
32581
cst363/lab/1994-census-summary.sql
Normal file
32581
cst363/lab/1994-census-summary.sql
Normal file
File diff suppressed because it is too large
Load Diff
16
cst363/lab/patients.sql
Normal file
16
cst363/lab/patients.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
drop table if exists patient;
|
||||
|
||||
create table patient (
|
||||
patient_no integer primary key,
|
||||
last_name varchar(64) not null,
|
||||
first_name varchar(64) not null,
|
||||
sex varchar(1) not null,
|
||||
date_of_birth varchar(8) not null,
|
||||
ward integer not null
|
||||
);
|
||||
|
||||
insert into patient values(454, "Smith", "John", "M", "14.08.78", 6);
|
||||
insert into patient values(223, "Jones", "Peter", "M", "07.12.85", 8);
|
||||
insert into patient values(597, "Brown", "Brenda", "F", "17.06.61", 3);
|
||||
insert into patient values(234, "Jenkins", "Alan", "M", "29.01.72", 7);
|
||||
insert into patient values(244, "Wells", "Chris", "F", "25.02.95", 6);
|
||||
BIN
cst363/lab/single-table-queries-2-lab.pdf
Normal file
BIN
cst363/lab/single-table-queries-2-lab.pdf
Normal file
Binary file not shown.
BIN
cst363/lab/table.pdf
Normal file
BIN
cst363/lab/table.pdf
Normal file
Binary file not shown.
@@ -3,12 +3,12 @@
|
||||
## Relational Algebra and its relation to SQL
|
||||
|
||||
### SELECT
|
||||
Used to select rows from some table.
|
||||
Used to select columns from some table.
|
||||
|
||||
> Relational symbol: sigma
|
||||
|
||||
### Projection
|
||||
Picks out the columns of a (set of) table(s)
|
||||
Picks out the rows of a (set of) table(s)
|
||||
|
||||
> Relational symbol: pi
|
||||
|
||||
|
||||
15
cst363/lec/lec4.md
Normal file
15
cst363/lec/lec4.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# lec4
|
||||
|
||||
|
||||
## Lab*
|
||||
|
||||
This lecture has some lab questions in the `lab/` dircory named `table1.pdf` *and* some example data called `patients.sql`.
|
||||
`table1.pdf` will have some exercises to learn the basic commands of sqlite and `patients.sql` should have some example data which _table1_ asks you to query.
|
||||
|
||||
## Serverless
|
||||
|
||||
Instead of having listen server listen for requests to perform actions upon these requests we simply have some databse held on a machina and we perform all of our sql commands on that machine.
|
||||
|
||||
For now we'll be dealing with small test db's so that we can practice the commands and observe each one's behavior; this will give you a good feeling of what does what in sqlite3.
|
||||
|
||||
|
||||
39
cst363/lec/lec5.md
Normal file
39
cst363/lec/lec5.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# lec5
|
||||
|
||||
## Lab
|
||||
|
||||
This lecture will have a lab activity in `cst366/lab/1994-census-summary.sql` with instructions found in `single-table-queries-2-lab.pdf`.
|
||||
|
||||
|
||||
## Distinct Values
|
||||
|
||||
> Mininum - min(field)
|
||||
|
||||
Finds the smallest value in the given filed
|
||||
|
||||
> Maximum - max(field)
|
||||
|
||||
Find the largest value in th given field
|
||||
|
||||
Say we have a column where we know there are duplicate values but we want to konw what the distinct values in the column may be.
|
||||
SQLite3 has a function for that: `select distinct field, ... from table;`
|
||||
|
||||
> select substr(field, startIndex, length) ...
|
||||
|
||||
_Note_: the start index starts counting at `1` so keep in mind we are offset `+1`.
|
||||
|
||||
## Joins
|
||||
|
||||
Now we want to join to tables together to associate their respective data.
|
||||
Important to note that a simple join does not necessarily take care of duplicate fields.
|
||||
If we have duplicate fields we must denote them as `target.field`.
|
||||
Here target is the table with the desired table and field is the desired field.
|
||||
|
||||
## Type Casting
|
||||
|
||||
If we have say `56` we can use a cast to turn it into an integer.
|
||||
|
||||
> cast(targetString as integer)
|
||||
|
||||
This will return with an error if a non number character is given as input to the cast function, here in this example we denote it with `targetString`.
|
||||
|
||||
Reference in New Issue
Block a user