0% found this document useful (0 votes)
5 views

SQL Statements and Operators

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

SQL Statements and Operators

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Consider a data set of the Indian census containing at least a billion rows, with data on every

individual's height, weight, monthly income, and hundreds of more such attributes. How do you
even start with the analysis of such an extensive data set to capture any trends in the data? The SQL
clauses that you will learn in this segment and throughout this session will help you with this.

So, in this segment, you will learn about the basic constructs of the SELECT query. You will
specifically learn about the following:

• 'Select' Clause
• 'From' Clause
• 'Where' Clause
• Operators: Arithmetic, Comparison and Logical

-- -----------------------------------------------------------------------------------------------------------------
-- Session: Querying in SQL
-- Basic SQL Queries

-- 1. Print the entire data of all the customers.


select *
from cust_dimen;

-- 2. List the names of all the customers.


select Customer_Name
from cust_dimen;

-- 3. Print the name of all customers along with their city and state.
select Customer_Name, City, State
from cust_dimen;

-- 4. Print the total number of customers.


select count(*) as Total_Customers
from cust_dimen;

-- 5. How many customers are from West Bengal?


select count(*) as Bengal_Customers
from cust_dimen
where State = 'West Bengal';

-- 6. Print the names of all customers who belong to West Bengal.


select Customer_Name,
from cust_dimen
where State = 'West Bengal';

-- -----------------------------------------------------------------------------------------------------------------
-- Operators

-- 1. Print the names of all customers who are either corporate or belong to Mumbai.
select Customer_Name, Customer_Segment, City
from cust_dimen
where Customer_Segment = 'Corporate' or City = 'Mumbai';
-- 2. Print the names of all corporate customers from Mumbai.
select Customer_Name, Customer_Segment, City
from cust_dimen
where Customer_Segment = 'Corporate' and City = 'Mumbai';

-- 3. List the details of all the customers from southern India: namely Tamil Nadu, Karnataka,
Telangana and Kerala.
Select *
from cust_dimen
where State in ('Tamil Naidu', 'Karnataka', 'Kerela', 'Telengana')

-- 4. Print the details of all non-small-business customers.


select *
from cust_dimen
where Customer_Segment != 'Small Business';

-- 5. List the order ids of all those orders which caused losses.
select ord_id, profit
from market_fact_full
where profit < 0;

-- 6. List the orders with '_5' in their order ids and shipping costs between 10 and 15.
select ord_id, shipping_cost
from market_fact_full
where ord_id like '%\_5%' and shipping cost between 10 and 15;

You might also like