Skip to content

Commit 5d194a0

Browse files
authored
Merge branch 'main' into formatting-fixes
2 parents 97f14d3 + c083f7f commit 5d194a0

8 files changed

+37
-27
lines changed

episodes/01-introduction.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ The main data types that are used in doaj-article-sample database are `INTEGER`
167167
Different database software/platforms have different names and sometimes different definitions of data types, so you'll need to understand the data types for any platform you are using. The following table explains some of the common data types and how they are represented in SQLite; [more details available on the SQLite website](https://www.sqlite.org/datatype3.html).
168168

169169
| Data type | Details | Name in SQLite |
170-
| :--------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------------- |
170+
| :--------------------- |:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| :-------------------------------------------------------------------------------------------------------------------- |
171171
| boolean or binary | this variable type is often used to represent variables that can only have two values: yes or no, true or false. | doesn't exist - need to use integer data type and values of 0 or 1. |
172-
| integer | sometimes called whole numbers or counting numbers. Can be 1,2,3, etc., as well as 0 and negative whole numbers: -1,-2,-3, etc. | INTEGER |
172+
| integer | sometimes called whole numbers or counting numbers. Can be 1, 2, 3, etc., as well as 0 and negative whole numbers: -1, -2, -3, etc. | INTEGER |
173173
| float, real, or double | a decimal number or a floating point value. The largest possible size of the number may be specified. | REAL |
174174
| text or string | any combination of numbers, letters, symbols. Platforms may have different data types: one for variables with a set number of characters - e.g., a zip code or postal code, and one for variables with an open number of characters, e.g., an address or description variable. | TEXT |
175175
| date or datetime | depending on the platform, may represent the date and time or the number of days since a specified date. This field often has a specified format, e.g., YYYY-MM-DD | doesn't exist - need to use built-in date and time functions and store dates in real, integer, or text formats. See [Section 2.2 of SQLite documentation](https://www.sqlite.org/datatype3.html#date_and_time_datatype) for more details. |

episodes/03-filtering.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ SQL is a powerful tool for filtering data in databases based on a set of conditi
2525
```sql
2626
SELECT *
2727
FROM articles
28-
WHERE ISSNs='2056-9890';
28+
WHERE ISSNs = '2056-9890';
2929
```
3030

3131
We can add additional conditions by using `AND`, `OR`, and/or `NOT`. For example, suppose we want the data on *Acta Crystallographica* published after October:
3232

3333
```sql
3434
SELECT *
3535
FROM articles
36-
WHERE (ISSNs='2056-9890') AND (Month > 10);
36+
WHERE (ISSNs = '2056-9890') AND (Month > 10);
3737
```
3838

3939
Parentheses are used merely for readability in this case but can be required by the SQL interpreter in order to disambiguate formulas.

episodes/04-ordering-commenting.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ Consider the following query:
5656
```sql
5757
SELECT *
5858
FROM articles
59-
WHERE (ISSNs = '2076-0787') OR (ISSNs = '2077-1444') OR (ISSNs = '2067-2764|2247-6202');
59+
WHERE (ISSNs = '2076-0787') OR (ISSNs = '2077-1444')
60+
OR (ISSNs = '2067-2764|2247-6202');
6061
```
6162

6263
SQL offers the flexibility of iteratively adding new conditions but you may reach a point where the query is difficult to read and inefficient. For instance, we can use `IN` to improve the query and make it more readable:
@@ -79,7 +80,8 @@ join multiple tables because they represent a good example of using
7980
comments in SQL to explain more complex queries.*/
8081

8182
-- First we mention all the fields we want to display
82-
SELECT articles.Title, articles.First_Author, journals.Journal_Title, publishers.Publisher
83+
SELECT articles.Title, articles.First_Author, journals.Journal_Title,
84+
publishers.Publisher
8385
-- from the first table
8486
FROM articles
8587
-- and join it with the second table.

episodes/05-aggregating-calculating.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ but only for the journals with 5 or more citations on average.
9494
SELECT ISSNs, AVG(Citation_Count)
9595
FROM articles
9696
GROUP BY ISSNs
97-
HAVING AVG(Citation_Count)>=5;
97+
HAVING AVG(Citation_Count) >= 5;
9898
```
9999

100100
:::::::::::::::::::::::::
@@ -106,9 +106,10 @@ HAVING AVG(Citation_Count)>=5;
106106
In SQL, we can also perform calculations as we query the database. Also known as computed columns, we can use expressions on a column or multiple columns to get new values during our query. For example, what if we wanted to calculate a new column called `CoAuthor_Count`:
107107

108108
```sql
109-
SELECT Title, ISSNs, Author_Count -1 as CoAuthor_Count
109+
SELECT Title, ISSNs, Author_Count - 1 as CoAuthor_Count
110110
FROM articles
111111
ORDER BY CoAuthor_Count DESC;
112+
112113
```
113114

114115
In section [6\. Joins and aliases](06-joins-aliases.md) we are going to learn more about the SQL keyword `AS` and how to make use of aliases - in this example we simply used the calculation and `AS` to represent that the new column is different from the original SQL table data.

episodes/06-joins-aliases.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ We will cover [relational database design](08-database-design.md) in the next ep
5454
When joining tables, you can specify the columns you want by using `table.colname` instead of selecting all the columns using `*`. For example:
5555

5656
```sql
57-
SELECT articles.ISSNs, journals.Journal_Title, articles.Title, articles.First_Author, articles.Month, articles.Year
57+
SELECT articles.ISSNs, journals.Journal_Title, articles.Title,
58+
articles.First_Author, articles.Month, articles.Year
5859
FROM articles
5960
JOIN journals
6061
ON articles.ISSNs = journals.ISSNs;
@@ -63,7 +64,8 @@ ON articles.ISSNs = journals.ISSNs;
6364
Joins can be combined with sorting, filtering, and aggregation. So, if we wanted the average number of authors for articles on each journal, we can use the following query:
6465

6566
```sql
66-
SELECT articles.ISSNs, journals.Journal_Title, ROUND(AVG(articles.Author_Count), 2)
67+
SELECT articles.ISSNs, journals.Journal_Title,
68+
ROUND(AVG(articles.Author_Count), 2)
6769
FROM articles
6870
JOIN journals
6971
ON articles.ISSNs = journals.ISSNs
@@ -142,16 +144,18 @@ We can alias both table names:
142144
```sql
143145
SELECT ar.Title, ar.First_Author, jo.Journal_Title
144146
FROM articles AS ar
145-
JOIN journals AS jo
147+
JOIN journals AS jo
146148
ON ar.ISSNs = jo.ISSNs;
147149
```
148150

149151
And column names:
150152

151153
```sql
152-
SELECT ar.title AS title, ar.first_author AS author, jo.journal_title AS journal
154+
SELECT ar.title AS title,
155+
ar.first_author AS author,
156+
jo.journal_title AS journal
153157
FROM articles AS ar
154-
JOIN journals AS jo
158+
JOIN journals AS jo
155159
ON ar.issns = jo.issns;
156160
```
157161

episodes/09-create.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ For example, a better definition for the `journals` table would be:
5454

5555
```sql
5656
CREATE TABLE "journals" (
57-
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
58-
"ISSN-L" TEXT,
59-
"ISSNs" TEXT,
60-
"PublisherId" INTEGER,
57+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
58+
"ISSN-L" TEXT,
59+
"ISSNs" TEXT,
60+
"PublisherId" INTEGER,
6161
"Journal_Title" TEXT,
6262
CONSTRAINT "PublisherId" FOREIGN KEY("PublisherId") REFERENCES "publishers"("id")
6363
);
@@ -90,6 +90,7 @@ CREATE TABLE "myjournals"(Journal_Title text, ISSNs text);
9090
INSERT INTO "myjournals"
9191
SELECT Journal_Title, ISSNs
9292
FROM journals;
93+
9394
```
9495

9596
Modifying existing records is done using the `UPDATE` statement.

episodes/11-extra-challenges.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ How many `articles` are there from each `First_author`? Can you make an alias fo
3535
## Solution 1
3636

3737
```sql
38-
SELECT First_Author, COUNT( * ) AS n_articles
38+
SELECT First_Author, COUNT(*) AS n_articles
3939
FROM articles
4040
GROUP BY First_Author
4141
ORDER BY n_articles DESC;
@@ -56,7 +56,7 @@ How many papers have a single author? How many have 2 authors? How many 3? etc?
5656
## Solution 2
5757

5858
```sql
59-
SELECT Author_Count, COUNT( * )
59+
SELECT Author_Count, COUNT(*)
6060
FROM articles
6161
GROUP BY Author_Count;
6262
```
@@ -77,10 +77,10 @@ language is unknown.
7777
## Solution 3
7878

7979
```sql
80-
SELECT Language, COUNT( * )
80+
SELECT Language, COUNT(*)
8181
FROM articles
8282
JOIN languages
83-
ON articles.LanguageId=languages.id
83+
ON articles.LanguageId = languages.id
8484
WHERE Language != ''
8585
GROUP BY Language;
8686
```
@@ -101,10 +101,10 @@ number of citations for that `Licence` type?
101101
## Solution 4
102102

103103
```sql
104-
SELECT Licence, AVG( Citation_Count ), COUNT( * )
104+
SELECT Licence, AVG(Citation_Count), COUNT(*)
105105
FROM articles
106106
JOIN licences
107-
ON articles.LicenceId=licences.id
107+
ON articles.LicenceId = licences.id
108108
WHERE Licence != ''
109109
GROUP BY Licence;
110110
```
@@ -124,12 +124,13 @@ Write a query that returns `Title, First_Author, Author_Count, Citation_Count, M
124124
## Solution 5
125125

126126
```sql
127-
SELECT Title, First_Author, Author_Count, Citation_Count, Month, Year, Journal_Title, Publisher
127+
SELECT Title, First_Author, Author_Count, Citation_Count,
128+
Month, Year, Journal_Title, Publisher
128129
FROM articles
129130
JOIN journals
130-
ON articles.issns=journals.ISSNs
131+
ON articles.issns = journals.ISSNs
131132
JOIN publishers
132-
ON publishers.id=journals.PublisherId;
133+
ON publishers.id = journals.PublisherId;
133134
```
134135

135136
:::::::::::::::::::::::::

episodes/Bonus_GoodStyle.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ SELECT articles.Title, articles.First_Author, journals.Journal_Title, publishers
4040
Into something that looks like this:
4141

4242
```sql
43-
SELECT articles.Title, articles.First_Author, journals.Journal_Title, publishers.Publisher
43+
SELECT articles.Title, articles.First_Author, journals.Journal_Title,
44+
publishers.Publisher
4445
FROM articles
4546
JOIN journals
4647
ON articles.ISSNs = journals.ISSNs

0 commit comments

Comments
 (0)