Writing a SQL Code on Editor
SQL Editor is a versatile feature of Report V2 which lets you write Simple to Complex SQL Code and create various kinds of reports on top of the SQL code's output data table.
It really comes in handy when you have a raw data table that you need to explore on the go and create reports on top of that.
Features of SQL Editor
SQL Editor Window: This is the main section where you can write and run Simple/Complex SQL Queries using the raw data warehouse tables to get the desired data.
*Here you can write only the "SELECT" SQL statements not any DML statements like INSERT, UPDATE, etc. For eg: "Select * from employees".
The idea is to let you explore tables that are present in your data warehouse.
Output Window: This is where the output of your SQL code will populate after clicking on the Run button. You can use it to go through the data and cross-check it. The Errors (if any) while executing your code would also appear here.
Schema Browser: This allows to search any table along with its schema that is present in the configured Data Warehouse.
You can easily type the required table name in the Search bar and it will give you the list of all the columns and their data types present in the mentioned table. You can double-click on the column name/table name to add it to the code.
Variables Panel: This allows you to add any new Local variables and see the existing list of Local and Global variables. Variables are useful to provide values to your code during the run-time to get the required data.
Visualization Panel: This allows you to switch to the reporting part using which you can create various kinds of reports on top of the output data of your SQL Code.
Build a Report using SQL Editor
Let's say you have an Order_details raw table which you need to modify first using some SQL query and then use the final table to perform some analysis like "Product Category wise Total Orders".
Click on “+ Create Report” and choose SQL Editor.
Give a name to the Report and now you will land on the Report V2 -SQL Editor UI.
Now in the SQL Editor tab write the SQL query which you want to use to modify the Order_details table and click the Run button.
For eg: If you want to analyze only the North region order's data and also want to combine order_id and location_id columns to create a new column tracking_id then you can write the following Code
Select a.*, concat(a.order_id,'-',a.location_id) as tracking
id
from orders_
details
where a.region ='North';
You will now have a final table as the Output of the above SQL query.
Now go to the Visualization Tab below the Schema Browser tab and choose the Pie Chart option.
In the Build panel go to the Chart Setting section and select Measure column Count of Order_id in the Values section and select Product Category column in the Labels section.
Click on the Visualize Button and your Pie Chart will be ready showcasing "Product Category wise Total Orders" for only the North region as you required.
Write with AI (Beta)
Ask AI feature empowers you to harness the power of your data with the simplicity of natural language. By translating your questions into SQL code, Ask AI streamlines your data analysis process, saving you time and effort.
How it Works
Access the Ask AI Feature:
Locate the "Ask AI" button at the top of your SQL Reports screen.
Write Your Question:
Click the "Ask AI" button to open the modal.
In the "Ask a Question" field, clearly articulate your data query using natural language. For example, "What is the total revenue by product category?"
Select Relevant Tables:
Choose the tables your query requires. You can select all tables by default or manually select specific tables or schemas.
Use the search bar to quickly find tables.
Generate SQL Code:
Click the "Generate" button to let Ask AI create the SQL code based on your question and table selection.
While generating, a loader and progress messages will be displayed. You can stop the generation process by clicking the "Stop" button.
Review and Use the Generated SQL:
Once generated, the SQL code will appear in the code script component.
Copy the SQL code using the "Copy SQL" button for further use.
Important Notes
Ask AI is currently in beta and may not always produce accurate results.
The generated SQL code is based solely on the provided question and table selection.
Only SELECT statements are supported at this time.
Last updated