Querying our data

DataLab with SQL

Jasmin Ludolf

Senior Data Science and AI Content Developer, DataCamp

The dataset

|sale_date |sales_rep|region|sales_amount|...|region_and_sales_rep|
|----------|---------|------|------------|---|--------------------|
|2025-02-03|Bob      |North |     5053.97|...|North-Bob           |
|2025-04-21|Bob      |West  |     4384.02|...|West-Bob            |
|2025-09-21|David    |South |     4631.23|...|South-David         |
|2025-08-24|Bob      |South |     2167.94|...|South-Bob           |
|2025-03-24|Charlie  |East  |      3750.2|...|East-Charlie        |
|2025-02-11|Charlie  |West  |     3761.15|...|West-Charlie        |
|2025-04-11|Bob      |West  |      618.31|...|West-Bob            |
...
1 https://www.kaggle.com/datasets/vinothkannaece/sales-dataset/data
DataLab with SQL

Sample query

GIF of DataLab showing a CSV file being dragged into a new workbook

DataLab with SQL

Querying our data

Generated sample query

SELECT *
FROM sales_data.csv;
|product_id|sale_date |sales_rep|...
|----------|----------|---------|...
|1052      |2025-02-03|Bob      |...
|1093      |2025-04-21|Bob      |...
|1015      |2025-09-21|David    |...
...

(Full output not shown)

Modified query

SELECT COUNT(*) AS count_all
FROM sales_data.csv;
|count_all|
|---------|
|     1000|
  • Hit run or Ctrl + Enter
DataLab with SQL

Querying our data

GIF of DataLab showing the query being modified and run again

DataLab with SQL

SQL cell headers

GIF on DataLab showing the first header in a SQL cell

DataLab with SQL

SQL cell headers

GIF on DataLab showing the second header in a SQL cell

DataLab with SQL

Modes

DataFrame mode

  • Return query output
  • Stores output as pandas DataFrame

Screenshot of the SQL cell highlighting the data frame name field

Query mode

  • Not available for DataFrames and CSVs
  • Returns a preview of the output
  • Saves the query for later use
  • Helpful when queries take time
  • Similar to using common table expressions
DataLab with SQL

Query mode with a sample dataset

GIF of DataLab showing a sample dataset on query mode

DataLab with SQL

Let's practice!

DataLab with SQL

Preparing Video For Download...