Product Analytics/Style guide

Who should use this guide
This document is a guide for anyone who is working with SQL/HiveQL queries in the product analytics team and the foundation, and would like to write clean and clear code that is meant to be shared and reused. For product analysts, these style conventions are mandatory for any publicly-available query.

General principles

 * Use spaces, not tab characters.
 * 2 space indent.
 * All SQL keywords in all caps.
 * Variable names are lowercase, with spaces represented by underscores ( not  ).

statements
Align all columns to the first column on their own line:

goes on its own line:

Always rename aggregates and function-wrapped columns:

Always rename all columns when selecting with table aliases:

Always use  to rename columns: