SQL Statements and Operators
SQL Statements and Operators
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
-- 3. Print the name of all customers along with their city and state.
select Customer_Name, City, State
from cust_dimen;
-- -----------------------------------------------------------------------------------------------------------------
-- 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')
-- 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;