7
7
- [ Accessing data with queries] ( #accessing-data-with-queries )
8
8
- [ Basic queries] ( #basic-queries )
9
9
- [ Filtering] ( #filtering )
10
- - [ ** Challenge 1** : Large bois ] ( #challenge-1-large-bois )
10
+ - [ ** Challenge 1** ] ( #challenge-1 )
11
11
- [ Building complex queries] ( #building-complex-queries )
12
12
- [ Sorting] ( #sorting )
13
13
- [ ** Challenge 2** ] ( #challenge-2 )
@@ -95,9 +95,9 @@ and atomic transactions. It eliminates ambiguity by forbidding NULLs.
95
95
96
96
4 . Solution: Normalize the data by breaking it into multiple tables
97
97
98
- | Animals | Sightings |
99
- | ------------------------------| --------------------------------|
100
- | ![ ] ( images/animals_half.png ) | ![ ] ( images/sightings_half.png ) |
98
+ Animals Sightings
99
+ ------------------------------ --------------------------------
100
+ ![ ] ( images/animals_half.png ) ![ ] ( images/sightings_half.png )
101
101
102
102
- Every row of every table contains unique information
103
103
- Normalization is a continuum. We could normalize this data
@@ -214,7 +214,7 @@ and atomic transactions. It eliminates ambiguity by forbidding NULLs.
214
214
WHERE (species_id = 'DM') OR (species_id = 'DO') OR (species_id = 'DS');
215
215
` ` `
216
216
217
- # # **Challenge 1**: Large bois
217
+ # # **Challenge 1**
218
218
219
219
Get all of the individuals in Plot 1 that weighed more than 75 grams,
220
220
telling us the date , species id code, and weight (in kg).
@@ -558,7 +558,7 @@ sqlite3 # enter sqlite prompt
558
558
` ` `
559
559
560
560
` ` ` sql
561
- select * from species where taxa = = 'Rodent';
561
+ SELECT * FROM species WHERE taxa = 'Rodent';
562
562
` ` `
563
563
564
564
2 . Output to .csv file
@@ -569,7 +569,7 @@ sqlite3 # enter sqlite prompt
569
569
` ` `
570
570
571
571
` ` ` sql
572
- select * from species where taxa = = 'Rodent';
572
+ SELECT * FROM species WHERE taxa = 'Rodent';
573
573
` ` `
574
574
575
575
` ` ` bash
@@ -588,47 +588,47 @@ sqlite3 # enter sqlite prompt
588
588
589
589
2 . Import libraries
590
590
591
- ` ` ` {.r org-language="R"}
591
+ ` ` ` r
592
592
library("DBI")
593
593
library("RSQLite")
594
594
` ` `
595
595
596
596
3 . FYI, use namespaces explicitly
597
597
598
- ` ` ` {.r org-language="R"}
598
+ ` ` ` r
599
599
con <- DBI::dbConnect(RSQLite::SQLite(), "../data/portal_mammals.sqlite")
600
600
` ` `
601
601
602
602
4 . Show tables
603
603
604
- ` ` ` {.r org-language="R"}
604
+ ` ` ` r
605
605
dbListTables(con)
606
606
` ` `
607
607
608
608
5 . Show column names
609
609
610
- ` ` ` {.r org-language="R"}
610
+ ` ` ` r
611
611
dbListFields(con, "species")
612
612
` ` `
613
613
614
614
6 . Get query results at once
615
615
616
- ` ` ` {.r org-language="R"}
616
+ ` ` ` r
617
617
df <- dbGetQuery(con, "SELECT * FROM surveys WHERE year = 2000")
618
618
head(df)
619
619
` ` `
620
620
621
621
7 . Use parameterized queries
622
622
623
- ` ` ` {.r org-language="R"}
623
+ ` ` ` r
624
624
df <- dbGetQuery(con, "SELECT * FROM surveys WHERE year = ? AND (month > ? AND month < ?)",
625
625
params = c(2000, 4, 10))
626
626
head(df)
627
627
` ` `
628
628
629
629
8 . Disconnect
630
630
631
- ` ` ` {.r org-language="R"}
631
+ ` ` ` r
632
632
dbDisconnect(con)
633
633
` ` `
634
634
0 commit comments