Categories: SQL Tutorials

How do data analysts use SQL? | SQL Queries for Data Analysis

In my previous articles i have given the different SQL Queries examples- SQL for Testers, SQL for Business Analysts and so on. In this article i would like to give the idea about SQL queries for Data analysis.What do you mean by data analysis? -Data analysis is nothing but fetching the data for analysis purpose and we can utilize that data for taking business decisions.

SQL Queries for Data Analysis Examples :

In this section i will give you multiple examples of SQL queries which are mostly used for data analysis purpose. I will start with simple data analysis examples and will cover the complex examples as well. The main purpose of SQL queries to use for data analysis is for taking the business details very easily.

Simple Queries for data analysis :

  1. Fetch the data from table :

The simple select query is very useful to fetch the data from table. I would like to give the example for fetching the data from Table.

Example : If user wants to fetch and analyse the first 1000 records from employee table.

Select * from Employee where rownum <=1000;

The above query is used to fetch first 1000 records from Employee table.

PostgreSQL Solution :

Select * from Employee limit 1000;

2.Fetch the data where Profession is Engineer.

Select * from Employee where profession=’Engineer’;

The above query will fetch the data from employee table whose profession is ‘Engineer’.

3.Fetch the data where profession is Engineer or Doctor.

Select * from Employee where profession IN (‘Engineer’,’Doctor’);

4.Fetch the data from Employee table where Salary of employee is between 10000 to 30000.

Select E.*, from Employee E,Salary S where E.Emp_id=S.Emp_id and s.salary between 10000 and 30000;

5.Fetch the Employee name and Salary from the Employee and salary table.

Select E.Employee_name and S.Salary from Employee E,Salary S where E.Emp_id=S.Emp_id;

6.Fetch the distinct country name from Employee table.

Select distinct Country from Employee;

7.If you want to fetch the data for Employees whose country is Finland and city is Helsinki. (Example with AND Operator)

Select * from Employees where Country_name=’Finland’ and City_name=’Helsinki’.

8.Fetch the data for Employee where if Country is India then Salary in Rupees and Country is Finland Salary in Euros.

Example for Case When Statement

Select *,Case when Country=’India’ Then ‘Rupee’

when Country=’Europe’ Then ‘Euro’

Else ‘Dollars’ As “Currency”

from Employee;

9.Fetch the number of employees who are from Finland.

Select count(*) from Employee where country=’Finland’;

10.Fetch the number of employees countrywise.

Select Country_name, count(*) from Employee group by Country_name;

11.Fetch number of Employees countrywise where count of employee more than 1000.

Select Country_name, count(*) from Employee group by Country_name having count(*)>1000;

12.Fetch the Employees who are not assigned to any department.

Select * from Employees where department_name is null;

13.Fetch the employees whose country is Either ‘India’ or ‘USA’.

Select * from Employees where country =’India’ or Country=’USA’;

14.Fetch the Employees salariwise in descending order.

Select * from Employees order by salary desc;

These are some most important queries which are using for data analysis and management. I hope you will like this article on SQL Queries for Data analysis and hope it is helpful. If you have any questions related to SQL Queries for Data analysis kindly comment in to comments section.

Amit S

Oracle Consultant with vast experience in Oracle BI and PL/SQL Development. Amiet is the admin head of this website who contributes by preparing tutorials and articles related to database technologies. He is responsible to manage the content and front-end of the website.

Recent Posts

What is Root Cause Analysis (RCA) With real examples

In my previous article I have given details about application support engineer day to day…

1 month ago

Application Support Engineer Day to day responsibilities

In my previous articles I have given the roles and responsibilities of L1,L2 and L3…

1 month ago

What is mean by SLA ( Service Level Agreement) with Examples?

In my previous articles i have given the hierarchy of production support in real company…

1 month ago

What is Production support Hierarchy in organization?

In this article i would like to provide information about production support organization structure or…

1 month ago

What are roles and responsibilities for L3 Support Engineer?

In my previous article I have given roles for L1 and L2 support engineer with…

1 month ago

What are roles and responsibilities of L2 Engineer?

I have started this new series of how to become application support engineer. This article…

1 month ago