Learn how to create new tables, view table details, join tables, and extract specific data from tables using SQL statements in the SAP HANA database explorer.
Reminder: This tutorial is part of a mission, in which you will help Alex, the CEO of Best Run Travel, to answer a concrete business question with SAP HANA Cloud, SAP HANA database.
Alex needs to know the top 5 partners of their agency and wants to find out the days with maximum booking of each partner.
Step 1Open the SQL console and set the schema
โ
Go to the Instances tab in SAP HANA Cloud Central and open SQL Console.
Open DBX from HANA Cloud Central
You can also open the SQL console by right-clicking on a database name and selecting Open SQL console or by using the shortcut Ctrl+Alt+C.
Once the SQL console loads, ensure that the current schema is SFLIGHT by checking the top center of the console.
If not, copy and paste the following statement to the console and run it:
SQL
SETSCHEMASFLIGHT;
SQL Console, with highlight on Current Schema
You can also change the schema by clicking on the current schema name in the center of the console, selecting SFLIGHT from the list, and then clicking the Change button.
Second Option to Change Current Schema in SQL Console
The current schema will then display SFLIGHT.
Step 2Query the most popular travel agents
+
Let’s find out which of the Best Run Travel agents are most popular. For this, we will need the agency number and the booking details. This means we need to use the tables SBOOK and STRAVELAG.
First, our goal is to extract the total number of bookings made per agency. To achieve this, we will start by creating a new table SAGENCYDATA from the existing tables SBOOK and STRAVELAG.
The following query will create a new table and order the agencies based on their number of bookings. Copy and paste query to the console and then click on the Run button:
You can view the contents of this table by running the following query:
SQL
SELECT*FROMSAGENCYDATA;
This will show you the contents of the new table:
View contents of SAGENCYDATA
Step 3Join tables to find out which agency makes the most bookings
+
Join the tables STRAVELAG and SAGENCYDATA based on the column AGENCYNUM and extract the top 5 agencies from the result. This will give you the list of agency numbers, names, and the number of bookings for the top 5 agencies.
You can use the following query that will join the tables and select the top 5 entries:
To view all contents of this new table, you can again use the SELECT * FROM query:
SQL
SELECT*FROMSAGBOOKDAYS;
Now that you have created the 2 tables, join these tables based on the agency number (column AGENCYNUM). You also need to extract only the day with maximum number of bookings for each of the top 5 agencies. For this, use the following nested queries:
Now you can see that the most bookings for the top 5 agencies have been done on Thursdays.
Maximum days
Well done!
You have completed the sixth tutorial of this mission! You learned how to create new tables, view table details, join tables and extract specific data from tables using SQL statements in the SAP HANA database explorer. This way you were able to help Alex get the business inside they were looking for.
Since Alex needs to make these insights available to other departments in Best Run Travel, the next step is to create a calculation view to share these findings with other departments.
Learn in the next tutorial how to get started with SAP Business Application to start creating a calculation view.
Share feedback on this tutorial or join the conversation in SAP Community.
Submit detailed feedbackDiscuss in Community
Steps
Step 1 of 5
1. Open the SQL console and set the schema2. Query the most popular travel agents3. Join tables to find out which agency makes the most bookings4. Find out which days have the most bookings5. Knowledge Check
Joule
AI Notice
Joule is an AI assistant. Generative AI may produce inaccurate, incomplete, or biased information. Always verify important details before acting on them.
Conversations are sent to SAP-hosted large language models for processing. Do not include personal data, credentials, or confidential information in your messages.
Joule's responses are based on the SAP tutorial catalog and may not reflect the latest product changes. For authoritative guidance, consult the linked tutorials and official SAP documentation.