You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: episodes/01-introduction.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -167,9 +167,9 @@ The main data types that are used in doaj-article-sample database are `INTEGER`
167
167
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).
| 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 |
173
173
| float, real, or double | a decimal number or a floating point value. The largest possible size of the number may be specified. | REAL |
174
174
| 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 |
175
175
| 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. |
Copy file name to clipboardExpand all lines: episodes/03-filtering.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,15 +25,15 @@ SQL is a powerful tool for filtering data in databases based on a set of conditi
25
25
```sql
26
26
SELECT*
27
27
FROM articles
28
-
WHERE ISSNs='2056-9890';
28
+
WHERE ISSNs='2056-9890';
29
29
```
30
30
31
31
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:
32
32
33
33
```sql
34
34
SELECT*
35
35
FROM articles
36
-
WHERE (ISSNs='2056-9890') AND (Month >10);
36
+
WHERE (ISSNs='2056-9890') AND (Month >10);
37
37
```
38
38
39
39
Parentheses are used merely for readability in this case but can be required by the SQL interpreter in order to disambiguate formulas.
Copy file name to clipboardExpand all lines: episodes/04-ordering-commenting.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,7 +56,8 @@ Consider the following query:
56
56
```sql
57
57
SELECT*
58
58
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');
60
61
```
61
62
62
63
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
79
80
comments in SQL to explain more complex queries.*/
80
81
81
82
-- First we mention all the fields we want to display
Copy file name to clipboardExpand all lines: episodes/05-aggregating-calculating.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -94,7 +94,7 @@ but only for the journals with 5 or more citations on average.
94
94
SELECT ISSNs, AVG(Citation_Count)
95
95
FROM articles
96
96
GROUP BY ISSNs
97
-
HAVINGAVG(Citation_Count)>=5;
97
+
HAVINGAVG(Citation_Count)>=5;
98
98
```
99
99
100
100
:::::::::::::::::::::::::
@@ -106,9 +106,10 @@ HAVING AVG(Citation_Count)>=5;
106
106
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`:
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.
@@ -63,7 +64,8 @@ ON articles.ISSNs = journals.ISSNs;
63
64
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:
0 commit comments