
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Retrieve Top 3 Highest and Lowest Revenue Menu IDs
/ 25
Join Tables to Retrieve Menu Item Names
/ 25
Format the total revenue column to two decimal places
/ 25
Fix the error and retrieve the top 10 small menu items
/ 25
Imagine you are a data analyst and have been with Data Beans for a few months. You have worked on a few successful projects with your teammates and have been assigned your first solo project. You are starting to create more complex queries with little help, but you have been asked to write more complex queries to retrieve deeper insights. Everyone on the team is helpful, but you need to start showing that you are more self-sufficient in your work.
You have read that BigQuery SQL code generation, explanation, and transformation may help you to write more complex queries using natural language. And, if you get stuck with writing a new query, you have also learned you could use Gemini to help review and debug your code. It could even help you with suggestions to resolve issues. Using these features will help you to be more independent in your work and, perhaps, even more efficient. However, you are not sure how to get started.
In this lab, you learn how to:
Finally, you will have time to reflect on what you have learned in this lab and consider how you could apply the code generation, explanation, transformation, and suggestions with your data, use cases, and workflows by answering questions in your Lab Journal.
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details pane.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
In this task, you review the menu and order_item table schemas.
In the Google Cloud console, on the Navigation menu, click BigQuery.
Click DONE on the Welcome dialog.
In the Explorer panel, expand the coffee_on_wheels
dataset at the bottom of the list.
Expand the coffee_on_wheels dataset. You see the menu
table.
Click the menu table. You see the menu
schema displayed.
Review the details of the schema.
Answer this question:
Which fields use FLOAT as datatype?
Click the order_item table. You see the order_item
schema displayed.
Review the details of the schema.
Answer this question:
Which fields use INTEGER as the data type?
In this task, you generate a SQL query using a natural language prompt to find menu IDs and total revenue for the top three and bottom three items in the menu by total revenue.
Click to create a new SQL Query. A new tab is displayed in BigQuery Studio.
Click to access the SQL generation tool. You see the Generate SQL with Gemini dialog appear. You can enter a natural language prompt in this window to generate a new SQL statement.
Enter the prompt below.
Click Generate. You see Gemini create a SQL statement like the one below.
Select the query.
Click immediately to the left of the query.
Click Explain this query.
You see the dialog for Gemini open to the right of BigQuery Studio.
Click Start chatting. You can see an explanation for the query like the one below in the chat window.
Review the explanation. Gemini provides a summary of the response like the following:
Click RUN. The result is six menu items, the top three highest-selling items and the bottom three lowest-selling items.
Click Check my progress to verify the objective.
The query you created in the previous task is helpful, but it is missing some critical information. For example, you don't know the menu item name, and there are extraneous decimal places in the total_revenue column.
To get the menu item name, you will have to join the menu and order item tables. You can also format the total_revenue field so that only two decimal places are displayed.
In this task, you use the transform feature of Gemini to write prompts to address these gaps.
Click the to create a new SQL query. A new tab is displayed in BigQuery Studio.
Click to access the SQL generation tool. You see the Generate SQL with Gemini dialog. You can enter a natural language prompt in this window to generate a new SQL statement.
Enter the prompt below.
Click Generate. You see Gemini create a SQL statement like the one below.
Click INSERT. The query you generated is added to the Untitled query tab.
Select the query.
Click immediately to the left of the query.
Click Explain this query. You see the explanation displayed in the Gemini chat window with a summary like the one below:
Review the details of the explanation.
Click RUN. The result is six menu items, the top three highest-selling items and the bottom three lowest-selling items. However, this time, you not only see the menu_id and total_revenue fields, you also see the item name field included between them.
Answer these questions:
Click Check my progress to verify the objective.
Select the query.
Click to access the SQL generation tool.
Click Transform. You see the Transform SQL with Gemini pop-up appear.
Enter the following prompt.
Click GENERATE. You see the new query generated.
Click INSERT. You see the new query in the Untitled query tab.
Click RUN. Notice how the result is very similar. However, now the total revenue field only has two decimal places.
What is the total revenue generated by Clouds of Coffee Delight?
Considering your data and use cases for BigQuery, how would you use the code generation feature?
Click Check my progress to verify the objective.
When you use Gemini with BigQuery you also have the ability to review and debug code. When you may have an error, you can use Gemini to suggest changes to improve your code, so there aren't errors.
Your teammate created the following SQL code:
Their goal was to retrieve the top ten small-sized items by total revenue from the coffee_on_wheels
dataset, including the menu_id
, item_name
, and total_revenue
fields.
However, with this SQL code, your teammate states they get this error:
And they are unable to resolve the issue.
Your task is to use Gemini and the coffee_on_wheels
dataset to resolve issues with this SQL code that was generated by your team member.
Click the to create a new SQL query.
Enter the query below.
Click RUN. You confirm the query fails to run and you get the following error:
Access the Gemini Chat window in BigQuery.
In the chat window, enter the following question.
Press <SHIFT><ENTER>, or <SHIFT><return> on Mac, to create a new line in the chat window.
Select the query and copy it.
Paste it immediately after the question you asked.
Press <SHIFT><ENTER>, or <SHIFT><return> on Mac, to create a new line in the chat window.
Enter the following sentence:
Click . You get a response from Gemini.
Review the suggestions in the response.
Based upon these suggestions, you determine the most likely cause of the issue is the correct dataset name coffee_on_wheels
is not specified within the INNER JOIN statement for the menu table in the query.
Within the suggestions, a refined query with a potential solution similar to the one below is provided:
Copy the refined query.
Click to open a new untitled query tab.
Paste the refined query in the new untitled query tab.
Click RUN. The result is each of the top 10 small menu items with the item name and the total revenue.
This is very close to what your teammate wanted. However, there is one small missing piece to the refined query. Notice that the total_revenue field is formatted with extraneous decimal places. You can ask gemini to correct this for you with the steps below.
In the chat window, ask Gemini the following prompt.
Press <SHIFT><ENTER>, or <SHIFT><return> on Mac, to create a new line in the chat window.
Select the query and copy it.
Paste it immediately after this first part of the prompt.
Press <SHIFT><ENTER>, or <SHIFT><return> on Mac, to create a new line in the chat window.
Add the following text to the end of the prompt.
Confirm the prompt now looks something like this:
Click . You see Gemini's response below.
With an explanation like the one below:
Copy the refactored code.
Click to open a new untitled query tab.
Paste the refactored query in the new untitled query tab.
Click RUN. The result is each of the top 10 small menu items with the item name and the total revenue.
You confirm the results are what is desired and send the query back to your teammate. They thank you for your help.
Answer this question: "What is the name of the item with the 5th most revenue? Also, how much revenue did it generate?
Considering your data and use cases, how would you use the code review and suggestion features to fix code you are struggling with?
Click Check my progress to verify the objective.
You have generated a SQL query with a natural language prompt and used code explanation to understand queries you are unfamiliar with. You have also used Gemini to help you review and debug code. You asked Gemini to help you with suggestions to improve or even fix your code. You are becoming more experienced with using Gemini in BigQuery to author queries with and without code. Now you even have experience troubleshooting queries. You are becoming more confident with BigQuery each day and can use Gemini to supplement your knowledge and skills.
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual last updated on March 28, 2025
Lab last tested on March 28, 2025
Copyright 2025 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one