Sql Excel : FORMATTING SQL QUERIES

There is no agreed-upon standard for formatting SQL queries. There are a few
good practices, such as:
Use table aliases that are abbreviations for the table name.
Use as to define column aliases.
Be consistent in capitalization, in usage of underscores, and in indentation.
Write the code to be understandable, so you and someone else can read it.
Writing readable code is always a good idea.
Any guidelines for writing code necessarily have a subjective element. The
goal should be to communicate what the query is doing. Formatting is
important: Just imagine how difficult it would be to read text without
punctuation, capitalization, and paragraphs.
The code in this book (and on the companion website) follows additional rules
to make the queries easier to follow.
Most keywords are capitalized and most table and column names use
CamelBack casing (except for ZipCensus).
The high-level clauses defined by the SQL language are all aligned on the
left. These are WITH, SELECT, FROM, WHERE, GROUP BY, HAVING, and ORDER BY.
Within a clause, subsequent lines are aligned after the keyword, so the
scope of each clause is visually obvious.
Subqueries follow similar rules, so all the main clauses of a subquery are
indented, but still aligned on the left.
Within the FROM clause, table names and subqueries start on a new line (the
tables are then aligned and easier to see). The ON predicate starts on its
own line, and the join keywords are at the end of the line.
Columns are generally qualified, meaning that they use table aliases.
Operators generally have spaces around them.
Commas are at the end of a line, just as a human would place them.
Closing parenthesis—when on a subsequent line—is aligned under the
opening parenthesis.
CASE statements are always surrounded by parentheses.
The goal should be to write queries so other people can readily understand
them. After all, you may be returning to your queries one day and you would
like to be able to quickly figure out what they are doing.