2. Build your first queries
Last updated
Last updated
You've seen some examples, you've scoped out your project, and you're ready to get going. The first thing you'll want to do is get some data into the canvas. To do this you'll need to start adding cells.
On this page, we'll be looking at:
The 3 ways to add cells to your canvas
SQL cells
Python cells
To add data directly from the side bar, drag or click "Add to canvas" when you hover over a table or column. You can add data either from your database (in the Tables pane), or from other cells (in the Cells pane).
If you add a table to your canvas, a cell will be created containing a simple SELECT statement.
If you add a column, a visual will be created containing a simple query to represent the distribution of the column.
Select the type of cell you want from the tool bar, and then add the cell to the canvas.
One of the unique features of the Count canvas is the ability to reference other cells - effectively turning your analysis into a DAG of connected queries. Instead of building messy, complex queries across several tabs in a SQL IDE, visualizing your analysis as a DAG helps because:
You can debug a query easily by isolating each subquery or CTE
You can copy and paste parts of the DAG for fast iteration and testing
The logical steps are easier to follow compared to reading complex nested SQL
Select a cell and hover near one of the edges and a plus icon will appear. Click the plus icon to choose which type of cell to create:
Each SQL cell is analagous to a tab of a SQL IDE.
Count can execute any SQL SELECT statement.
Queries are sent directly to your database, and results are retrieved and shown in the canvas, so use the same syntax you would in your database or SQL IDE.
To run a query you can:
Click away from the cell
Use the Shift + Enter keyboard shortcut
Click the Run cell button in the floating cell controls
Format the SQL in your cell using the Format SQL button in the Design bar
The cell name is the identifier used in code to refer to the cell - ensure that it is a helpful name!
You can also add a cell title to help others understand what the cell represents
In Count you're not limited to SQL only! Combine SQL with Python to bring a world of opportunity to your analysis.
To learn more about using python in the canvas, see our docs here.