Skip to content

Commit 11a8c5f

Browse files
authored
Merge pull request #5 from rozhnev/patch-3
Fix SQL formatting and add syntax highlighting
2 parents e75506c + 9ebe03b commit 11a8c5f

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

mariadb-dev-04-data-manipulation-and-extraction.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@ license_url: "https://creativecommons.org/licenses/by-nc-sa/4.0/"
3232
Be careful of the overuse of functions in OLTP use cases where it may be better to add a column such as a virtual column that contains calculations already rendered
3333

3434
```sql
35-
SELECT CONCAT(name_first, SPACE(1), name_last) AS 'Name',
36-
37-
(DAYOFYEAR(birthdate) - DAYOFYEAR(CURDATE())) / 12 AS 'Months to Birthday'
38-
35+
SELECT
36+
CONCAT(name_first, SPACE(1), name_last) AS 'Name',
37+
(DAYOFYEAR(birthdate) - DAYOFYEAR(CURDATE())) / 12 AS 'Months to Birthday'
3938
FROM clients
40-
4139
LIMIT 1;
4240
```
4341

@@ -53,7 +51,9 @@ Columns with Operators can be Specified to Filter Results
5351
SELECT Name, Population
5452
FROM City
5553
WHERE Population > 1000000;
54+
```
5655

56+
```shell
5757
+-------------+------------+
5858
| Name | Population |
5959
+-------------+------------+
@@ -95,7 +95,7 @@ WHERE CountryCode = 'FIN'
9595
LIMIT 2, 3;
9696
```
9797

98-
```sql
98+
```shell
9999
+-------------------+-----------+
100100
| Name | District |
101101
+-------------------+-----------+
@@ -109,25 +109,31 @@ LIMIT 2, 3;
109109

110110
Data can be Ordered and Broken into Blocks
111111

112-
`SELECT cols`
113-
`FROM table`
114-
`WHERE clause`
115-
`ORDER BY col`
116-
`LIMIT offset, count;`
112+
```sql
113+
SELECT cols
114+
FROM table
115+
WHERE clause
116+
ORDER BY col
117+
LIMIT offset, count;
118+
```
117119

118120
Basic Syntax Example for `SELECT` Statement with `ORDER BY` Clause
119121

120-
`SELECT Name, Population`
121-
`FROM City`
122-
`WHERE Population > 1000000`
123-
`ORDER BY Population`
124-
`LIMIT 0, 3;`
122+
```sql
123+
SELECT Name, Population
124+
FROM City
125+
WHERE Population > 1000000
126+
ORDER BY Population
127+
LIMIT 0, 3;
128+
```
125129

130+
```shell
126131
| Name | Population |
127132
|---------|------------|
128133
| Zapopan | 1,012,563 |
129134
| Napoli | 1,002,079 |
130135
| Perm | 1,070,162 |
136+
```
131137

132138
### Ascending and descending order
133139

@@ -141,8 +147,9 @@ No descending indexes however B+ Tree indexes can be used to optimize sort or ra
141147
SELECT Name, District FROM City
142148
WHERE CountryCode = 'FIN'
143149
ORDER BY District DESC, Name ASC;
150+
```
144151

145-
152+
```shell
146153
| Name | District |
147154
|----------------|------------------|
148155
| Turku [Åbo] | Varsinais-Suomi |
@@ -162,7 +169,9 @@ Useful with Aggregate Functions to Create Sub-Groups
162169
SELECT Continent, SUM(Population)
163170
FROM Country
164171
GROUP BY Continent;
172+
```
165173

174+
```shell
166175
+---------------+------------------+
167176
| Continent | SUM(Population) |
168177
+---------------+------------------+
@@ -745,4 +754,4 @@ Or using subqueries used for accessing hierarchical data
745754
- 5-6 Using Common Table Expressions
746755
- 5-7 Using Window Functions
747756
- 5-8 Rolling Back a Transaction
748-
- 5-9 Observing a Deadlock
757+
- 5-9 Observing a Deadlock

0 commit comments

Comments
 (0)