Query Datasets
Dataset Type - Query Datasets
Section titled “Dataset Type - Query Datasets”You may create a new dataset by querying existing datasets. This feature is particularly useful if you would like to modify your exisitng data or join data from two datasets.
-
Click on Home —> Datasets.
-
Click on the “+ Add New Dataset” button, and select “Query Datasets”.
-
Enter the SQL query you would like to perform, and press the Run Query button. There are a few examples of queries to follow below.
-
Alternatively, you may use the built-in help function to generate a SQL query. Select which dataset you’d like to query, and write the question or command you are thinking of. Cast will generate a query based on your input.
In this example, we selected Sample Contacts - Copy 19 as the dataset. Our command was, “List all the contacts with renewal authority.”Cast returned the query SELECT * FROM dataset_15067 WHERE renewal_authority = 1;
-
Check the Query Execution Preview. When you are satisfied, give your new dataset a name and press the Save button.
Example Queries
Section titled “Example Queries”Clean up data
Section titled “Clean up data”SELECT -- Replace with the columns from your dataset id, name, CASE WHEN gender = 'Male' THEN 'M' WHEN gender IS NULL THEN 'U' WHEN gender = '' THEN 'U' ELSE 'F' END AS gender_no_emptyFROM -- Replace with your dataset dataset_XXXXX as "Dataset_Name";Rename columns
Section titled “Rename columns”SELECT -- Replace with the columns to rename from your dataset "__internal.__id" as idFROM -- Replace with your dataset dataset_XXXXX as "Dataset_Name";Pivot dataset
Section titled “Pivot dataset”SELECT category, -- get the category column SUM(CASE WHEN quarter = 'Q1' THEN amount ELSE 0 END) AS 'Q1', -- pivot Q1 sales SUM(CASE WHEN quarter = 'Q2' THEN amount ELSE 0 END) AS 'Q2', -- pivot Q2 sales SUM(CASE WHEN quarter = 'Q3' THEN amount ELSE 0 END) AS 'Q3', -- pivot Q3 sales SUM(CASE WHEN quarter = 'Q4' THEN amount ELSE 0 END) AS 'Q4' -- pivot Q4 salesFROM -- Replace with your sales dataset dataset_XXXXX as "Sales_Dataset_Name"GROUP BY category;Join data from two datasets
Section titled “Join data from two datasets”-- Get the customer's name and the count of their support ticketsSELECT "Customers_Dataset".name, COUNT("Tickets_Dataset".id) as ticket_countFROM -- Replace with your customers dataset dataset_XXXXX as "Customers_Dataset"JOIN -- Replace with your tickets dataset dataset_XXXXX as "Tickets_Dataset"ON "Customers_Dataset".id = "Tickets_Dataset".customer_idGROUP BY "Customers_Dataset".id;