Best Practice: SQL Formatting
Data and analytics should be here to guide us in our daily decisions, in order to do that though, data needs to be clearly defined, trusted, and easily digestible for everyone. Here is a brief overview on our best practices for formatting SQL.
Structured Query Language (SQL) is a programming language that is used to manage relational databases and perform various operations on the data in them. It's used to modify database tables and index structures, add update and delete rows of data, retrieve subsets of data and more.
General Rules
Common Table Expression (CTE)
Structure and Comments
Recommended by LinkedIn
Naming Conventions
Long Lines
On long lines (eg: CASE WHEN) use a logical point for wrapping the line manually. Some options:
a) Align the WHEN keywords
b) Split on operator
c) One line per parameter to a function
We are a data analytics consultancy who use SQL and python everyday. If you need an extra hand in optimising your data pipeline, why not get in touch and see if we can help?