Skip to content

Instantly share code, notes, and snippets.

@ryantuck
Created October 1, 2019 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryantuck/72d48d82076d7dd14a9bd0459061722f to your computer and use it in GitHub Desktop.
Save ryantuck/72d48d82076d7dd14a9bd0459061722f to your computer and use it in GitHub Desktop.
Idea for writing a SQL query in yaml
from:
base: orders
joins:
- name: items
type: inner
on: items.order_id = orders.id
- name: products
type: inner
on: products.id = items.product_id
- name: shipments
type: left
on: shipments.order_id = orders.id
where:
- orders.placed >= '2019-09-01'
select:
dimensions:
product_name: products.name
measures:
total_orders:
type: count_distinct
sql: orders.id
average_price:
type: average
sql: items.amount
not_yet_shipped:
type: count
sql: case when shipments.id is true then 1 else 0 end
order_by:
- name: total_orders
type: desc
limit: 50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment