Analyzing Business 'Spaces': Meta Forum Review


#1

After reviewing much of the forum questions for 'SQL: Analyzing Business Metrics' it would appear that anyone having issues with their code, when it looks 'perfect tot he naked eye', I would suggest adding/removing spaces in code like the following examples (Spaces substituted with _'s ):

ROUND(table.col,_#) --> ROUND(table.col,#)
ROUND(SUM(table.col),#) --> ROUND(SUM(table.col),_#)
COUNT_(table.col) --> COUNT(table.col)
etc.

Basically, first look at anything with Brackets involved. Think BEDMAS but only B.

After trying that to no avail (IF no avail), then start moving clauses to new lines. For example:
/****Attempt 1****/
SELECT COUNT(ordered_at) FROM orders GROUP BY 1 ORDER BY 1;

/****Attempt 2****/
SELECT COUNT(ordered_at)
FROM orders GROUP BY 1 ORDER BY 1;

/****Attempt 3****/
SELECT COUNT(ordered_at)
FROM orders
GROUP BY 1 ORDER BY 1;

/****Attempt 4****/
SELECT COUNT(ordered_at)
FROM orders
GROUP BY 1
ORDER BY 1;

Addendum: "Don't get cocky kid." Don't assume your code is correct. That's a loaded assumption.