SQL examples and functions
1. SQL examples and functions
Some metrics need exact formulas that Genie can't infer. Let's explore SQL examples and functions.2. When Genie needs help
Consider a question like "What is the top revenue-generating product?" Genie might guess at the grouping and aggregation, but you want it to follow your exact pattern every time. This is where SQL examples come in.3. Function vs. Query
Register a function when you have specific, repeatable math or logic that applies to a single value, like a 15% Bakery Bulk Discount. Register it so Genie applies it consistently. Write an example query when you need structural patterns involving multiple tables or complex filters, for example, joining sales_customers to sales_transactions to find customers who haven't shopped in two weeks.4. Creating a SQL example
To create a SQL example, you provide two things: a natural language description, phrased the way users actually ask, like "Identify the top revenue-generating product,"5. Creating a SQL example
and the verified SQL that should run when that question is asked. Genie matches incoming questions against your descriptions and uses your exact SQL pattern instead of generating its own. The better your description matches how users phrase questions, the more reliably your example gets triggered.6. Coming up: Trusted Assets
SQL examples are a powerful teaching tool, but some metrics are too important to leave any room for interpretation. For those mission-critical KPIs, Genie offers Trusted Assets, verified queries that lock down your exact SQL. Unlike regular examples where Genie might adapt the pattern, a Trusted Asset runs your approved code every time. We'll dive deep into creating and using Trusted Assets in the next chapter.7. Let's practice!
Practice creating SQL examples for complex KPIs and explore when SQL functions versus example queries are the right choice. Let's go!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.