From 8c3d628348e86c4274091c92c0b2934de3cbbc3b Mon Sep 17 00:00:00 2001 From: "@andatoshiki" Date: Thu, 4 Apr 2024 10:47:38 -0700 Subject: [PATCH] doc(cis105): add lecture note for lecture 14 on sql statements & add its affiliated sidebar hyperlink components for quick accesses --- docs/.vitepress/config/sidebar.ts | 4 ++ .../cis105/cis105-l14-lecture-note.md | 72 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 docs/academic/cis105/cis105-l14-lecture-note.md diff --git a/docs/.vitepress/config/sidebar.ts b/docs/.vitepress/config/sidebar.ts index eac2045e..a94edc9c 100644 --- a/docs/.vitepress/config/sidebar.ts +++ b/docs/.vitepress/config/sidebar.ts @@ -225,6 +225,10 @@ export const sidebar: DefaultTheme.Config['sidebar'] = { { text: 'Lect 13: Information Systems in Business', link: '/academic/cis105/cis105-l13-lecture-note', + }, + { + text: 'Lect 14: More SQL Statements', + link: '/academic/cis105/cis105-l14-lecture-note' } ], }, diff --git a/docs/academic/cis105/cis105-l14-lecture-note.md b/docs/academic/cis105/cis105-l14-lecture-note.md new file mode 100644 index 00000000..d6df2c57 --- /dev/null +++ b/docs/academic/cis105/cis105-l14-lecture-note.md @@ -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 +