0% found this document useful (0 votes)
5 views2 pages

How SQL Should Look Like

The document provides a comprehensive SQL syllabus with examples focusing on proper formatting and syntax. It includes examples of clean SQL code using Common Table Expressions (CTEs), JOINs, and window functions, along with formatting tips for readability. Additionally, it emphasizes the importance of visual style in SQL code to enhance professionalism and maintainability.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

How SQL Should Look Like

The document provides a comprehensive SQL syllabus with examples focusing on proper formatting and syntax. It includes examples of clean SQL code using Common Table Expressions (CTEs), JOINs, and window functions, along with formatting tips for readability. Additionally, it emphasizes the importance of visual style in SQL code to enhance professionalism and maintainability.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Complete SQL Syllabus with Examples (Colored)

How SQL Code Should Look Like

-- This section explains how good SQL looks like in terms of formatting and syntax

-- - Example 1: Clean SELECT with CTE


WITH high_earners AS (
SELECT
emp_id,
name,
salary
FROM employees
WHERE salary > 70000
)
SELECT *
FROM high_earners;

-- - Example 2: Proper JOIN with aliases


SELECT
e.name,
d.department_name,
e.salary
FROM employees e
JOIN departments d ON e.department_id = d.department_id
WHERE e.salary > 60000;

-- - Example 3: Using window functions with formatting


WITH ranked_orders AS (
SELECT
emp_id,
order_amount,
RANK() OVER (PARTITION BY emp_id ORDER BY order_amount DESC) AS order_rank
FROM orders
)
SELECT * FROM ranked_orders WHERE order_rank = 1;

-- - Formatting Tips:
-- - Always capitalize SQL keywords (SELECT, FROM, WHERE, etc.)
-- - Break long queries into readable lines
-- - Use indentation inside CTEs or subqueries
-- - Comment your logic with --
-- - Use aliases for tables when joining multiple sources
-- - Separate clauses like WHERE, GROUP BY, ORDER BY onto new lines

-- - Visual Style (as seen in most editors)


-- Keywords: SELECT, FROM, WHERE --> Blue
-- Strings: 'Sales', '2023-01-01' --> Green or Orange
-- Functions: COUNT(), AVG(), RANK() --> Purple
-- Column names: salary, department_id --> Black or Default
-- Aliases: e, d --> Black or Grey
Complete SQL Syllabus with Examples (Colored)

-- This formatting not only looks professional but also makes code easier to debug and maintain.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy