The data grid and the SQL scratchpad
Filter and search rows without code, then ask the same question in SQL and keep the query.
What runs in CodeSplash
- Descriptive statistics Verified in Python and R
You will be able to
- Filter, sort and search rows in the data grid
- Run a query on the SQL page and read its Results, Messages and Plan tabs
- Save a query and turn a result into a dataset
Read first
Two ways to ask
ReadThe Data page (⌘2) answers questions by pointing: sort a column, filter it, search everything. The SQL page (⌘4) answers the questions pointing cannot, such as a grouped summary or a join.
Both read the same warehouse, so anything you do in one is available in the other.
Palmer penguinsPoint at the rows
In the appOpen the penguins dataset on the Data page.
- Click the
body_massheader to sort it. - Filter
speciesto Gentoo. - Press the toolbar's Copy the SQL for this view button.
The copied SQL is the same query the grid ran. Paste it into a SQL tab and you have a starting point you did not have to write.
Header summaries, sorting and paging all happen in the warehouse, so a grid stays quick on millions of rows.
How many have no recorded sex?
PredictPredict first
The penguins dataset has 344 rows. How many birds have no recorded sex? Commit a guess, then run the query in the next step.
Make your guess between 0 and 50 birds, then reveal.
Reveal
Eleven. In the grid you would filter for empty cells; in SQL the query below counts them. Two of those birds also have no measurements at all, which you would miss from a summary of one column.
Ask in SQL
In the appPress Query on the dataset. A new tab opens with a starter query. Replace it with this and press Run (⌘↵):
SELECT count(*) - count(sex) AS no_sex
FROM palmer_penguins_sample;
palmer_penguins_sample is the table the sample becomes. Your own tables are listed in the Schema panel, where Insert puts a name in the editor for you.
Below the editor, Results shows rows, Messages shows errors and timings, and Plan appears after Explain. The walkthrough below writes a grouped query: the average {{value}} for each {{group}}.
A grouped question
ExploreNow ask something the grid cannot show in one view. Run this, then change species to island and run it again:
SELECT species,
count(*) AS n,
round(avg(body_mass), 1) AS mean_mass
FROM palmer_penguins_sample
GROUP BY species
ORDER BY mean_mass DESC;
A GROUP BYGROUP BYSplits rows into groups that share values, so that each aggregate is computed once per group. collapses the rows to one per group. You will see Gentoo penguins are heavier by about 1,300 grams.
Every tab keeps its own session, so a temporary table in one tab does not disturb another.
Keep what you found
ReadThree buttons in the toolbar keep a query's value:
- Save names it, so it appears in the Saved panel. Queries you ran are in History anyway.
- Notebook gives you Python or R code that loads the result as a data frame.
- Model saves it as a SQL model the warehouse can rebuild, with data checks.
Above the rows in Results, Save as dataset keeps the result itself, as a new dataset or the next version of an existing one.
Check your understanding
CheckpointCheck yourself
You want mean body mass for each species and island combination. Where is the quickest place?
Show the answer
Answer: b
Grouped summaries are what SQL is for. Sorting shows you rows, not a summary of them.
Check yourself
count(*) is 344 and count(sex) is 333. How many rows have no value for sex?
Show the answer
Answer: 11
count(*) counts rows; count(sex) counts rows where sex is not NULL. The difference is the number of missing values.
Take the next step
ReflectThe grouped query shows a difference between species. Is it bigger than chance alone would produce? A summary cannot tell you, and that is the moment to leave SQL for Analyze.
Recap
Recap- The grid is for pointing at rows; SQL is for grouped questions and joins.
- Copy the SQL for this view turns grid clicks into a query.
- Save, Notebook and Model keep a query's work beyond the tab.
Concepts in this lesson