mirror of
https://github.com/andatoshiki/toshiki-notebook.git
synced 2026-06-06 09:16:45 +00:00
doc(cis105): add lecture note for lecture 14 on sql statements & add its affiliated sidebar hyperlink components for quick accesses
This commit is contained in:
parent
b66af1811b
commit
8c3d628348
@ -225,6 +225,10 @@ export const sidebar: DefaultTheme.Config['sidebar'] = {
|
|||||||
{
|
{
|
||||||
text: 'Lect 13: Information Systems in Business',
|
text: 'Lect 13: Information Systems in Business',
|
||||||
link: '/academic/cis105/cis105-l13-lecture-note',
|
link: '/academic/cis105/cis105-l13-lecture-note',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Lect 14: More SQL Statements',
|
||||||
|
link: '/academic/cis105/cis105-l14-lecture-note'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
72
docs/academic/cis105/cis105-l14-lecture-note.md
Normal file
72
docs/academic/cis105/cis105-l14-lecture-note.md
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
# CIS105: Computer Applications & Information Systems Lect. 14
|
||||||
|
|
||||||
|
## Chapter 14: More SQL Statement
|
||||||
|
|
||||||
|
### 14.1: Statement Review
|
||||||
|
|
||||||
|
- `SELECT`: What **fields** (column) you want
|
||||||
|
- `fieldname`: If the name is used in only one table
|
||||||
|
- `FROM`: What table or tables contain the fields
|
||||||
|
- `ORDER BY`: Sorting
|
||||||
|
- `DISTINCT`: Use after `SELECT` when you only want to show each vale of the selected field(s) once
|
||||||
|
- `LIMIT`: Use when you want to limit the number of records produced
|
||||||
|
|
||||||
|
### 14.2: New SQL Statements
|
||||||
|
|
||||||
|
- `WHERE`: Applies conditions, filters
|
||||||
|
|
||||||
|
- `WHERE` clause conditions follow a pattern: field + comparison operator + value
|
||||||
|
|
||||||
|
- ```sql
|
||||||
|
WHERE crime.iucr_no = 420
|
||||||
|
```
|
||||||
|
|
||||||
|
- Comparison Operators:
|
||||||
|
|
||||||
|
- `>` : Returns all records larger than the specified value
|
||||||
|
- `>=`: Returns all records that are at least as large as the specified value (including the value)
|
||||||
|
- `<` : Returns all records smaller than the specified value
|
||||||
|
- `<=`: Returns all records that are at least as small as the specified value (including the value)
|
||||||
|
- `=` : Returns all records that are exactly equal to the specified value
|
||||||
|
- `<>`: Returns all records that are not equal to the specified value
|
||||||
|
|
||||||
|
- `NULL`: An empty value
|
||||||
|
|
||||||
|
- `NOT`: Can be used to create a condition that reverses the logic of any condition
|
||||||
|
|
||||||
|
- Similar logic to the `NOT` function in Excel
|
||||||
|
|
||||||
|
- `AND`: Both conditions must be met for row to be included in query
|
||||||
|
|
||||||
|
- `OR`: Used to combine criteria when we want our results to mach any criteria
|
||||||
|
|
||||||
|
- `BETWEEN`: Shorthand way to include values in a range
|
||||||
|
|
||||||
|
- `IN`: Shorthand way to include values in a range
|
||||||
|
|
||||||
|
- `LIKE`: Use this statement when you aren't sure of the values in a record
|
||||||
|
|
||||||
|
- `%`: any combination of characters
|
||||||
|
|
||||||
|
- `%Keyword`: ends with keyword
|
||||||
|
- `%Keyword%`: looks for %keyword% anywhere in the record
|
||||||
|
- `Keyword%`: starts with keyword
|
||||||
|
|
||||||
|
- `-` substitutes for any single character
|
||||||
|
|
||||||
|
- '`t_p`' would return '`tip`', '`tap`', or '`top`''; but not '`stop`'
|
||||||
|
|
||||||
|
- '`p_st`" would return '`past`"', but not '`paste`'
|
||||||
|
|
||||||
|
- `'h__s_n'` would return '`hanson`', 'hensen', or 'hansen'; but not 'harrison' (note that
|
||||||
|
|
||||||
|
'h%s_n' would return 'harrison'
|
||||||
|
|
||||||
|
### 14.3: Rules to Remember
|
||||||
|
|
||||||
|
- To combine `AND` and `OR` statements, you must follow the order of operations (`AND` 1st, `OR` 2nd)
|
||||||
|
- If `OR` must be first, use `()`
|
||||||
|
- All words must be in between `('_')`, `("_")`
|
||||||
|
- If your value contains a quotation, use double quotation or a `/`
|
||||||
|
- All `#s` is left as-is
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user