SQL Problem Solving Functions & Use Cases (Data
Engineering)
1. Basic Queries
- SELECT – Retrieve data from table
- DISTINCT – Remove duplicates
- WHERE – Filter rows
- AND / OR / NOT – Logical conditions
- ORDER BY – Sort results
- TOP / LIMIT – Get top rows
- IN – Match values in list
- BETWEEN – Range filtering
- IS NULL – Check null values
2. String Functions
- LIKE – Search for text pattern
- PATINDEX – Search pattern (SQL Server)
- CHARINDEX – Find position of text
- LEN – Get string length
- LEFT / RIGHT – Extract characters
- SUBSTRING – Extract part of string
- REPLACE – Replace text
- TRIM – Remove spaces
- LOWER / UPPER – Change case
3. Aggregate Functions
- COUNT – Number of rows
- SUM – Total values
- AVG – Average
- MIN – Minimum
- MAX – Maximum
4. GROUP BY
- GROUP BY – Aggregate per group
- HAVING – Filter groups
5. JOINS
- INNER JOIN – Matching rows
- LEFT JOIN – All from left + matches
- RIGHT JOIN – All from right + matches
- FULL JOIN – All rows both tables
6. Window Functions
- ROW_NUMBER – Unique rank per row
- RANK – Rank with gaps
- DENSE_RANK – Rank without gaps
- LAG – Previous row
- LEAD – Next row
- SUM OVER – Running total
7. Date Functions
- GETDATE – Current date
- DATEADD – Add time
- DATEDIFF – Difference between dates
- YEAR / MONTH / DAY – Extract date parts
8. Data Cleaning
- COALESCE – Replace NULL
- ISNULL – Replace NULL
- CAST / CONVERT – Change data type
- NULLIF – Convert value to NULL
9. Set Operations
- UNION – Combine results
- UNION ALL – Combine including duplicates
- INTERSECT – Common rows
- EXCEPT – Difference between tables
10. CTE
- WITH (CTE) – Temporary result set
- Recursive CTE – Hierarchical data