SQL - Cheat sheet
99% of the SQL you write as a data analyst is not complex.
Most of it comes from a short list of simple skills.
Here is cheat sheet I assembled of must know SQL for analytics…
SELECT: The foundation of all SQL queries
- Allows you to retrieve the data
- Choose the columns you want to display in the SELECT statement
- Separate columns with a comma
WHERE: Filter your results based on criteria
- AND
- OR
- NOT
- IN (list)
- =, <, >, etc.
GROUP BY: Group rows that have the same values and aggregate data using aggregate functions
- COUNT
- SUM
- AVG
- MIN
- MAX
JOINS: Combine data from multiple tables to form a single output
- INNER JOIN
- LEFT JOIN
CASE WHEN: Allows you to perform conditional logic
- Example:
CASE
WHEN animal_type = 'Lion' THEN 'Carnivore'
WHEN animal_type = 'Giraffe' THEN 'Herbivore'
ELSE 'Omnivore'
END AS diet_type
WINDOW FUNCTIONS: Perform calculations across rows rather than just within a group by
- ROW_NUMBER
- RANK
- DENSE_RANK
- SUM
- ... OVER ( PARTITION BY x ORDER BY y)
DATE functions: Functions for working with dates
- EXTRACT
- DATE_ADD
- DATE_SUB
- DATE_DIFF
- CURRENT_DATE
- LAST_DAY
That's my list!
DHI₹EN

Comments
Post a Comment