Skip to content

Commit

Permalink
Draft of lesson 3
Browse files Browse the repository at this point in the history
  • Loading branch information
mattahrens committed Oct 4, 2023
1 parent a39c264 commit abb28cf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion docs/03-Querying-data-pivot-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,37 @@ If we want to query data to only retrieve a set of fields, then we can do that b

## Practice: Building a pivot table

To put this into practice, we will now build what is called a **pivot table** in Google Sheets. A pivot table allows us to take our dataset and query it using a simple interface. To get started, go to your Google Sheets with the Animal Data, then navigate to *Insert -> Pivot Table*. It gives you the option of where to create the pivot table, so you can choose to create it in a *New sheet*.
To put this into practice, we will now build what is called a **pivot table** in Google Sheets. A pivot table allows us to take our dataset and query it using a simple interface. To get started, go to your Google Sheets with the Animal Data, then navigate to *Insert -> Pivot Table*.

![image](images/03-insert_pivot_table.png)

It gives you the option of where to create the pivot table, so you can choose to create it in a *New sheet*. That will then create the pivot table in a new tab in your Google Sheet.

![image](images/03-create_new_sheet.png)

Once you have the new sheet with the pivot table, we can start to build a query. You will see a *Pivot table editor* on the right side of the Google Sheet and that is where we can pick what we want for our query. There are lots of parts of the editor which lets us query the data in different ways.

![image](images/03-pivot_table_editor.png)

To start, you can add the *name* field for Rows. After you do that, you will see the full list of names show up on the left side of the Google Sheet. In doing that, we have done a **selection** by choosing a specific field to show from the data.

![image](images/03-pivot_table_names.png)

To do a **filter**, we can go to the Filters part of the *Pivot table editor* and then select a field to use for our filter. Let's try to find animals that are airborne, so you can select the *airborne* field, and then navigate to the *Status* and click on *Show all items*. From there, you can uncheck the 0 value which will then filter for animals that are airborne because they have a value of 1. Press OK, and then you will see the names reduce to only those animals that are airborne.

![image](images/03-pivot_table_airborne.png)

Congratulations! You have completed your first query using a pivot table. Thinking back to how we defined a query as a question that you ask of a dataset, we can now map what our question was. In selecting the name field and then filtering by airborne animals, we asked the question of the dataset: What are the names of animals that are airborne? You can see how our question really was in two parts -- selecting what information we wanted (names) and then filtering what specific names we were looking for (airborne). This is the basic structure of how we query data.

## Practice: Building your own queries

Now it is time for you to figure out how to build your own queries using a pivot table. Here are 3 questions that you ask of our animals dataset and that you can get an answer using the pivot table:

- What are the names of animals that are predators?
- What are the names of animals that have fins and a tail? Hint: you'll have to add multiple filters.
- What is the total number of attributes for the animals by name? Hint: you'll have to use the *Values* part of the pivot table editor.

## Summary

A query is a question that you ask of a dataset. A basic query consists of selecting the fields that we want and filtering records based on what we want to see. A pivot table can be used to build a query in Google Sheets.

Binary file added docs/images/03-pivot-table-airborne.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/03-pivot-table-editor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/03-pivot-table-names.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit abb28cf

Please sign in to comment.