SQL examples and functions

Introduction to Databricks Genie

Gang Wang

Senior Data Scientist

When Genie needs help

nanobanana: half: AI assistant uncertain about revenue aggregation, question marks around grouping options

$$

"What is the top revenue-generating product?"

Genie might guess at the grouping and aggregation.

SQL examples ensure it follows your exact pattern every time.

Introduction to Databricks Genie

Function vs. Query

nanobanana: half: SQL Function for single value calculations vs Example Query for structural patterns with joins

SQL function when

  • Repeatable math or logic
  • Applies to a single value
  • Example: 15% bulk discount formula

Example query when

  • Structural patterns with joins
  • Multiple tables or complex filters
  • Example: customers who haven't shopped in 2 weeks
Introduction to Databricks Genie

Creating a SQL example

Natural language description

"Identify the top revenue-generating product"

Phrased how users actually ask

$$

Introduction to Databricks Genie

Creating a SQL example

Natural language description

"Identify the top revenue-generating product"

Phrased how users actually ask

Verified SQL

SELECT
  `product`,
  SUM(`totalPrice`) as total_revenue,
  COUNT(*) as transaction_count,
  SUM(`quantity`) as total_quantity_sold
FROM
  `samples`.`bakehouse`.`sales_transactions`
GROUP BY
  `product`
ORDER BY
  total_revenue DESC

Genie uses YOUR exact pattern

Introduction to Databricks Genie

Coming up: Trusted Assets

nanobanana: half: Gold shield with lock icon and SQL code, representing verified trusted query

$$

For mission-critical KPIs that need guaranteed accuracy, Genie offers Trusted Assets - verified queries that run your exact SQL every time.

We'll cover how to create and use them in Chapter 4.

Introduction to Databricks Genie

Let's practice!

Introduction to Databricks Genie

Preparing Video For Download...