SQLQuestions
SQLQuestions
ORDER_DATE
1/1/2011
1/6/2011
6/7/2011
12/21/2011
STATE
WA
OR
CA
IL
WA
Question 1: Please provide SQL for Customer Ids of customers who placed an
Order on 1/1/2011 .
Expected Output: ORDER_DATE, CUSTOMER_ID
Select ORDER_DATE, CUSTOMER_ID
From ORDERS
Where ORDER_DATE = 1/1/2011
Question 2: Please provide SQL for Customer Names of Customers who placed an
Order from WA State.
Expected Output: STATE, Customer Name
Select STATE, Customer_Name
From CUSTOMERS
Where STATE = WA
Question 3: Please provide SQL for Number Of Orders for various States.
Expected Output: STATE, Number_Of_Orders
Select State From CUSTOMER
Select Count(Order_ID) as NUMBER_Of_Orders From ORDERS
Group by State
Order by Count(Order_ID), DESC
Question 4: Please provide SQL for Customers who placed more than 5 orders.
Expected Output: Customer Name, Number_Of_Orders
Select Customer_Name From CUSTOMER
Select Count (Order_ID) as Number_Of_Orders From ORDERS
Where Number_Of_Orders > 5
Group by Customer_Name
Order by Count(Order_ID), DESC
Question 5: Please provide SQL for Customer(s) with the highest number of
order in 2012.
Expected Output: Customer Name, Number_Of_Orders
Select Customer_Name From CUSTOMER
Select Max(Numer_Of_Order)
From(Select Count (Order_ID) as Number_Of_Order From ORDERS)
Group by Customer Name
Question 6: Please provide SQL for Customer(s) who registered but never placed
an order.
Expected Output: Customer Name, State
Select Customer_Name, State
From CUTOMER
Join ORDERS On CUSTOMER. Customer_ID = ORDERS. Customer_ID
Where ORDERS. Customer_ID IS NULL
Question 7: I am trying to find customers who make repeat purchases. Please
provide SQL for Customer(s) who placed an order on 12/25/2012 and also on
12/25/2013.
Expected Output: Customer Name, State
Select Customer_Name, State
From CUSTOMER
Join ORDERS On CUSTOMER. Customer_ID = ORDERS. Customer_ID
Where Order_Date = 12/25/2012 and Order_Date = 12/25/2013,
Excel:
Please open the attached xls (DataSheet.xls) and make following changes. The xls has 3
worksheets Base Data, Intended Output - 1 and Intended Output - 2. The xls contains
Sales information for various items and the Merchants who sold those items. E.g. on Line 2,
on 1/1/2011 in the State of WA, 1 unit of item A1 was sold by Merchant M1 at 12$ .
Question 1:
On the Base Data sheet add a column called Week that is calculated based on OrderDate.
Question 2:
Using Pivot table please output the following fields for each State.
1. Count Of Merchants with a Sale
2. Count of Items with a Sale
3. Sum Of Units Sold
Question 3:
Using the Pivot table built on Question 2, create report similar to the one on Intended
Output - 1.
Question 4:
Using the Pivot table built on Question 2, create report similar to the one on Intended
Output - 2. The difference from the previous question is the drop down list on OrderDate. So
this presents the list of Order Dates from Base Data worksheet and upon selection will
update the values in the table.
Hint: You have to modify the Pivot Table to add OrderDate (in addition to State).