Successfully reported this slideshow.
Your SlideShare is downloading. ×

You Can Do It in SQL

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad

Check these out next

1 of 35 Ad

You Can Do It in SQL

Download to read offline

Just because you can, doesn’t mean you should. But in this case, you definitely should! Learn how this one weird trick (Jinja templating) will supercharge your analytics workflows and help you do more, better, faster with SQL.

Just because you can, doesn’t mean you should. But in this case, you definitely should! Learn how this one weird trick (Jinja templating) will supercharge your analytics workflows and help you do more, better, faster with SQL.

Advertisement
Advertisement

More Related Content

Slideshows for you (20)

Similar to You Can Do It in SQL (20)

Advertisement

More from Databricks (20)

Recently uploaded (20)

Advertisement

You Can Do It in SQL

  1. 1. You can do it in SQL
  2. 2. Drew Banin (he/him) Chief Product Officer 2 mo’ data mo’ problems @drewbanin on Twitter
  3. 3. ● Open core data modeling software ● dbt provides a SQL-first workflow for: - Data modeling - Data testing - Data documentation - And more! You can learn more at getdbt.com We’re the makers of dbt
  4. 4. Confessions & disclaimers ● I have never written a line of production Scala code in my life ● I have written a whole lot of SQL in my life ● People who tolerate Python packaging don’t get to complain about the JVM
  5. 5. I ❤ SQL , Expressive , Accessible , Universal , Declarative , Thought provoking….?
  6. 6. I ❤ SQL , Expressive - SQL reads more or less like a real sentence , Accessible , Universal , Declarative , Thought provoking….?
  7. 7. I ❤ SQL , Expressive , Accessible - Lots of people can learn in pretty quickly , Universal , Declarative , Thought provoking….?
  8. 8. I ❤ SQL , Expressive , Accessible , Universal - Most databases speak SQL with pretty consistent support , Declarative , Thought provoking….?
  9. 9. I ❤ SQL , Expressive , Accessible , Universal , Declarative - No moving parts, limited opportunities for the bad kind of magic , Thought provoking….?
  10. 10. I ❤ SQL , Expressive , Accessible , Universal , Declarative , Thought provoking….?
  11. 11. Some things you can do in SQL
  12. 12. Technique: Pivoting Columns
  13. 13. What: convert rows of data into columns of data Why: to derive new metrics from existing rows in a table Pivoting columns
  14. 14. What: convert rows of data into columns of data Why: to derive new metrics from existing rows in a table Pivoting columns user_id event_name happened_at 1 signup 2021-01-01 1 purchase 2021-01-02 2 signup 2021-01-03 3 signup 2021-01-04 3 purchase 2021-01-05 1 purchase 2021-01-05
  15. 15. What: convert rows of data into columns of data Why: to derive new metrics from existing rows in a table Pivoting columns user_id event_name happened_at 1 signup 2021-01-01 1 purchase 2021-01-02 2 signup 2021-01-03 3 signup 2021-01-04 3 purchase 2021-01-05 1 purchase 2021-01-05
  16. 16. What: convert rows of data into columns of data Why: to derive new metrics from existing rows in a table Pivoting columns user_id event_name happened_at 1 signup 2021-01-01 1 purchase 2021-01-02 2 signup 2021-01-03 3 signup 2021-01-04 3 purchase 2021-01-05 1 purchase 2021-01-05 user_id signup_date purchases 1 2021-01-01 2 2 2021-01-02 0 3 2021-01-04 1
  17. 17. Technique: Appending datasets
  18. 18. Unions What: append tables together Why: combine tables into a taller table
  19. 19. Unions What: append tables together Why: combine tables into a taller table user_id event_name happened_at 1 signup 2021-01-01 1 purchase 2021-01-02 2 signup 2021-01-03 user_id event_name happened_at 1 app_install 2021-01-01 1 screen_view 2021-01-02 2 app_install 2021-01-03 web_events mobile_events
  20. 20. Unions What: append tables together Why: combine tables into a taller table source user_id event_name happened_at mobile 1 app_install 2021-01-01 mobile 1 screen_view 2021-01-02 mobile 2 app_install 2021-01-03 web 1 signup 2021-01-01 web 1 purchase 2021-01-02 web 2 signup 2021-01-03 all_events
  21. 21. Technique: Window functions
  22. 22. Window functions What: apply transformations over part of a table Why: use cases abound!
  23. 23. Window functions What: apply transformations over part of a table Why: use cases abound! user_id happened_at page_path 1 2021-01-01 /product 1 2021-01-02 /signup 2 2021-01-03 /app pageviews
  24. 24. Window functions What: apply transformations over part of a table Why: use cases abound! user_id happened_at page_path 1 2021-01-01 /product 1 2021-01-02 /signup 2 2021-01-03 /docs pageviews user_id first_page_path 1 /product 2 /docs user_touches
  25. 25. Helpful window functions ● first_value ● last_value ● lag ● lead ● row_number ● rank ● sum ● min ● max ● avg ● count
  26. 26. When you write a lot of SQL...
  27. 27. SQL: The bad parts ● No “functions” for code reuse ● Lots of typing → lots of typos ● It might be the most copy/pasted language of all time! ○ Citation needed ● But…. what if we add templating?
  28. 28. ● Yes! ● Accessibility is 🔑 ● What happens when you teach people SQL? ○ Data (engineers|scientists|analysts) can collaborate in code ○ Non-engineers are empowered to understand business logic ○ More people can contribute! You can do it in SQL… but should you?
  29. 29. What does the future hold? ● More data workloads will converge around SQL ● Databases will improve support for sophisticated SQL operations - AI & ML? - Streaming? - ….? ● More roles will require SQL knowledge and aptitude ● More & better tools will exist to aid in writing and managing SQL
  30. 30. What do you think?

×