SQL is one of the most important programming languages to learn. It is essential for businesses to understand the general structure of it because data is becoming increasingly important for businesses today. If you are an analyst that looks at data or reports data to business stakeholders, it is absolutely critical that you understand SQL, learn it, and can do some basic SQL queries.

 

What Is SQL?

For those completely unfamiliar with SQL, let’s start here. SQL is a domain-specific programming language that is designed to manage data held in a database management system. Basically, SQL is used to communicate with the database.

 

The Importance of SQL

The primary reason why SQL is so important is because most of your data is going to be in a tabular format, and SQL is the best way to get your data out of that format. There are many tools out there where you can visually get data and run reports, which can be a powerful feature, but many of these tools are starting to allow the analysts to write SQL. This is because SQL is the most flexible way to get the data out of these systems.

 

Applying SQL to Real Scenarios

In order to illustrate the power of SQL, let’s run through a basic scenario of some information you may need to get. Say you are a small retailer with ten different stores in five different cities, and you want to get detailed information on your stores’ performances. Here’s the SQL code you would write to get key information from your data. You can do a query for total sales, sales by store, and sales by city.

 

Let’s assume the data you will query is stored in a database table named store_sales below:

 

SQL store sales

 

Here is what the SQL queries will look like to get the following data from the store_sales table above:

 

Get total sales

 

SELECT SUM(yearly_sales)

FROM store_sales

 

Results:

SQL yearly sales

 

Get sales for a particular store

 

SELECT store_number, city, yearly_sales

FROM store_sales

WHERE store_number = ‘006’

 

Results:

SQL sales per store

 

Get sales for a specific city

 

SELECT SUM(yearly_sales)
FROM store_sales
WHERE city = ‘Miami’

 

Results:

SQL yearly sales

 

The examples above are a simplified, somewhat unrealistic view of real-world the data. In reality, you could have thousands of stores in various countries, and you may also want to get more detailed information about individual sales. SQL can help you join data together from different tables/sources. To illustrate this, let’s look at a slightly more realistic example (although we are only scratching the surface).

 

We will use the same store_sales table as before.

SQL store sales

 

Let’s now have a store_transactions table that contains more details about each purchase at the stores.

 

SQL store transactions

 

With SQL, you can write a query that gives you the most popular category of items sold by city.

 

SELECT b.city, a.category, SUM(a.price) as total_sales
FROM store_transactions as a
JOIN store_sales as b on a.store_number = b.store_number
GROUP BY b.city, a.category
ORDER BY b.city;

 

Results:

SQL Category Results

 

Summary

The two examples above are just scratching the surface with what is possible with SQL. SQL can offer infinite possibilities to query your data, and it’s extremely important for analysts to learn it. Fortunately, there are plenty of resources available to help you learn SQL and get value out of your data immediately. Here’s are a few of those resources to help get you started.

 

 

Cognetik is a full-service data analytics company that can help you gain transformational insights from your data and take your business to the next level. We have a highly skilled team of analysts that can write any type of SQL you need to do advanced analyses so you can create dashboards, complete predictive analytics, and data science. As a result, our team will ensure that the data you collect is of the highest quality and as accurate as possible.

About the author

Jose Bergiste

Jose Bergiste
Jose loves all things analytics, software development, and product management. His wide range of experience from small startups to large Fortune 1000 companies has helped him gain a broad and deep knowledge of the industry. Jose’s passion is to help companies realize the full power of data and analytics to maintain and develop products that customers find delightful.

New eBook Release: A Guide to User Journey Analysis

Related Articles