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

The Essential Guide to Cryptocurrency Exchange Platform Development for Beginners and Beyond

Introduction Cryptocurrencies took the world by storm, setting up a new financial system and breaking…

5 months ago

Top 20 System Administrator Interview Questions and answers

In my previous article I have given Top 20 technical support interview questions with its…

7 months ago

Desktop Support Scenario Based Interview Questions

In my previous articles I have given 15 most asked desktop support interview questions with…

7 months ago

How Do Business Analysts Use SQL for Their Needs?

A business analyst is someone who is versed in processes of data analysis used for…

7 months ago

Top 15 Control-M Interview Questions with Answers

In my previous article I have already given top questions and answers for Desktop support…

7 months ago

Top 20 SQL Interview Questions for Production Support

In my previous article I have given unix production support interview questions and answers. In…

7 months ago