A simple SQL project demonstrating basic queries for analyzing employee and project data.
This project contains sample database tables and SQL queries I created to practice and demonstrate basic SQL skills. The database includes employees, departments, and projects with relationships between them.
- departments - Company departments and their locations
- employees - Employee information including salary and hire date
- projects - Company projects with status and dates
- employee_projects - Links employees to their assigned projects
create_tables.sql- Creates the database tablesinsert_data.sql- Adds sample data to the tablesportfolio_select_examples.sql- Example queries demonstrating different SQL techniques
- Basic SELECT queries with filtering and sorting
- JOIN operations to combine data from multiple tables
- Aggregate functions (COUNT, AVG, MAX, MIN)
- GROUP BY and HAVING clauses
- Subqueries
- CASE statements for conditional logic
- Common Table Expressions (CTEs)
The project includes 7 different queries:
- Find all Sales employees making over $50,000
- List employees with their department names (using JOIN)
- Count employees and calculate average salary by department
- Find employees earning above company average (using subquery)
- Show employees assigned to active projects
- Categorize employees by salary level (using CASE)
- Compare employee salaries to their department average (using CTE)
Query 1: Find all Sales employees making over $50,000
| employee_id | first_name | last_name | salary | |
|---|---|---|---|---|
| 102 | Sarah | Johnson | sarah.j@company.com | 62000 |
| 111 | Robert | Taylor | robert.t@company.com | 58000 |
| 101 | John | Smith | john.smith@company.com | 55000 |
Query 2: List employees with their department names
| employee_id | first_name | last_name | department_name | hire_date |
|---|---|---|---|---|
| 103 | Mike | Williams | Marketing | 2023-01-10 |
| 104 | Emily | Brown | Marketing | 2022-11-05 |
| 108 | Anna | Davis | HR | 2023-02-14 |
Query 3: Count employees and average salary by department
| department_id | employee_count | avg_salary | max_salary | min_salary |
|---|---|---|---|---|
| 3 | 3 | 75000 | 82000 | 68000 |
| 5 | 2 | 70000 | 71000 | 69000 |
| 1 | 3 | 58333 | 62000 | 55000 |
Query 4: Find employees earning above company average
| employee_id | first_name | last_name | salary |
|---|---|---|---|
| 106 | Lisa | Garcia | 82000 |
| 105 | David | Jones | 75000 |
| 109 | James | Miller | 71000 |
| 110 | Maria | Wilson | 69000 |
| 107 | Tom | Martinez | 68000 |
Query 5: Show employees assigned to active projects
| first_name | last_name | department_name | project_name | project_duration_days |
|---|---|---|---|---|
| Tom | Martinez | IT | Mobile App Launch | 305 |
| Lisa | Garcia | IT | Customer Database Upgrade | 128 |
| Mike | Williams | Marketing | Marketing Campaign Q3 | 91 |
Query 6: Categorize employees by salary level
| employee_id | first_name | last_name | salary | salary_grade |
|---|---|---|---|---|
| 108 | Anna | Davis | 45000 | Mid Level |
| 103 | Mike | Williams | 48000 | Mid Level |
| 104 | Emily | Brown | 51000 | Mid Level |
| 112 | Jennifer | Anderson | 53000 | Mid Level |
| 101 | John | Smith | 55000 | Mid Level |
Query 7: Compare employee salaries to their department average
| first_name | last_name | salary | department_name | avg_dept_salary | pct_of_avg |
|---|---|---|---|---|---|
| Sarah | Johnson | 62000 | Sales | 58333.33 | 106.29 |
| Robert | Taylor | 58000 | Sales | 58333.33 | 99.43 |
| Lisa | Garcia | 82000 | IT | 75000.00 | 109.33 |
| David | Jones | 75000 | IT | 75000.00 | 100.00 |
- Run
create_tables.sqlto create the tables - Run
insert_data.sqlto populate the tables with sample data - Try the queries in
portfolio_select_examples.sqlto see the results
- SQL (works with MySQL, PostgreSQL, or similar databases)
This is a learning project created to practice SQL fundamentals.