Skip to main content

SQL Examples

Use Magic to write, fix, and annotate your SQL queries

All of the following examples are real queries tested on our demo data. They should serve as good examples of what's possible, and as creative inspiration for you to start testing out Magic in your own workspace.

We test and evaluate Magic on these specific examples, so if you are seeing issues when replicating these, let us know at [email protected].

Query data with natural language

Magic is excellent at going from a plain language question to a functional SQL query. Precision is always helpful in prompts, but you'll be amazed at the kinds of things you can just casually ask for.

  • Just ask for top-level business metrics:

  • Or ask very specific questions:

  • Quickly identify outliers: You could rapidly iterate on this prompt either manually or with Magic to better define what an 'outlier' is.

  • Build a simple or complex funnel: Bonus tip: this prompt uses the specific table name technique to force Magic to query an ecommerce dataset rather than our other demo order data.

Date / timestamp operations

Magic is really good at things that require careful syntactic specificity, like datetime operations. Say what kind of filter or parsing you want in plain language, and watch dialect-specific code appear without ever loading up the documentation.

  • Easily applying complex date filters: Magic also knows common facts like holidays and seasons, so you can easily zero in on or remove particular parts of the year.
  • Converting between dialect-specific code:

Automate repetitive tasks

Magic can operate as a sort of turbocharged find+replace, either writing a complicated regex to actually do find-and-replace, or performing a more complex task like extrapolating an analysis out to other time periods.

  • Selecting all columns except a few:
  • Repeating variations on an operation many times:

Generate complex patterns

Magic is not limited to just simple repetitive operations or syntactical assists. Try asking for something complicated! Note that the more complex the ask, the more it helps to be specific in your prompt.

  • Building a daily active user/monthly active user calculator: This pattern requires a date spine table to be done correctly, which Magic successfully implements.
  • Identifying consecutive daily site visitors: This is a great example of a question that seems very simple, but actually requires a somewhat complex pattern.
  • Performing cohort analysis:

On this page