Introduction
In this project, you will learn how to calculate the average salary for each department in a database and display the results in descending order using SQL queries.
๐ Preview
MariaDB [edusys]> SOURCE ~/project/singleTableQuery.sql
+------------+--------------+
| dept_name | avg_salary |
+------------+--------------+
| Physics | 91000.000000 |
| Finance | 85000.000000 |
| Elec. Eng. | 80000.000000 |
| Comp. Sci. | 77333.333333 |
| Biology | 72000.000000 |
| History | 61000.000000 |
| Music | 40000.000000 |
+------------+--------------+
7 rows in set (0.001 sec)
๐ฏ Tasks
In this project, you will learn:
- How to start the MySQL server and import a database
- How to write an SQL query to group data by department and calculate the average salary
- How to order the results in descending order based on the average salary
๐ Achievements
After completing this project, you will be able to:
- Understand how to use SQL's
SELECT
, FROM
, WHERE
, GROUP BY
, and ORDER BY
clauses to perform data analysis
- Implement a SQL query to calculate and display the average salaries per department in descending order
- Apply your SQL knowledge to solve real-world data analysis problems
Skills Graph
%%%%{init: {'theme':'neutral'}}%%%%
flowchart RL
mysql(("MySQL")) -.-> mysql/BasicKeywordsandStatementsGroup(["Basic Keywords and Statements"])
sql(("SQL")) -.-> sql/DataManipulationandQueryingGroup(["Data Manipulation and Querying"])
mysql(("MySQL")) -.-> mysql/DatabaseFunctionsandDataTypesGroup(["Database Functions and Data Types"])
sql(("SQL")) -.-> sql/BasicSQLCommandsGroup(["Basic SQL Commands"])
mysql/BasicKeywordsandStatementsGroup -.-> mysql/use_database("Database Selection")
sql/BasicSQLCommandsGroup -.-> sql/select("SELECT statements")
sql/BasicSQLCommandsGroup -.-> sql/insert("INSERT INTO statements")
mysql/BasicKeywordsandStatementsGroup -.-> mysql/select("Data Retrieval")
mysql/BasicKeywordsandStatementsGroup -.-> mysql/source("External Code Execution")
sql/BasicSQLCommandsGroup -.-> sql/create_table("CREATE TABLE statements")
sql/DataManipulationandQueryingGroup -.-> sql/order_by("ORDER BY clause")
sql/DataManipulationandQueryingGroup -.-> sql/group_by("GROUP BY clause")
mysql/DatabaseFunctionsandDataTypesGroup -.-> mysql/database("DB Function - Info Retrieval")
subgraph Lab Skills
mysql/use_database -.-> lab-301284{{"Average Salaries Per Department "}}
sql/select -.-> lab-301284{{"Average Salaries Per Department "}}
sql/insert -.-> lab-301284{{"Average Salaries Per Department "}}
mysql/select -.-> lab-301284{{"Average Salaries Per Department "}}
mysql/source -.-> lab-301284{{"Average Salaries Per Department "}}
sql/create_table -.-> lab-301284{{"Average Salaries Per Department "}}
sql/order_by -.-> lab-301284{{"Average Salaries Per Department "}}
sql/group_by -.-> lab-301284{{"Average Salaries Per Department "}}
mysql/database -.-> lab-301284{{"Average Salaries Per Department "}}
end