sqlquestions

Post on 26-Sep-2015

212 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

sql

TRANSCRIPT

SQL:Please provide SQL queries based on the following tables.ORDERS Contains orders placed by CustomersORDERS

ORDER_ID (PK)CUSTOMER_ID (FK)ORDER_DATE

O1C11/1/2011

O2C11/6/2011

O3C26/7/2011

O4C312/21/2011

CUSTOMER Contains Customers registered on the websiteCUSTOMER

CUSTOMER_ID (PK)CUSTOMER_NAMESTATE

C1JackWA

C2JillOR

C3JasonCA

C4JimIL

C5JohnWA

Question 1: Please provide SQL for Customer Ids of customers who placed an Order on 1/1/2011 .Expected Output: ORDER_DATE, CUSTOMER_IDSelect ORDER_DATE, CUSTOMER_ID From ORDERSWhere ORDER_DATE = 1/1/2011Question 2: Please provide SQL for Customer Names of Customers who placed an Order from WA State.Expected Output: STATE, Customer NameSelect STATE, Customer_NameFrom CUSTOMERSWhere STATE = WAQuestion 3: Please provide SQL for Number Of Orders for various States.Expected Output: STATE, Number_Of_OrdersSelect State From CUSTOMERSelect Count(Order_ID) as NUMBER_Of_Orders From ORDERSGroup by StateOrder by Count(Order_ID), DESCQuestion 4: Please provide SQL for Customers who placed more than 5 orders.Expected Output: Customer Name, Number_Of_OrdersSelect Customer_Name From CUSTOMERSelect Count (Order_ID) as Number_Of_Orders From ORDERSWhere Number_Of_Orders > 5Group by Customer_NameOrder by Count(Order_ID), DESCQuestion 5: Please provide SQL for Customer(s) with the highest number of order in 2012.Expected Output: Customer Name, Number_Of_OrdersSelect Customer_Name From CUSTOMERSelect 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, StateSelect Customer_Name, StateFrom CUTOMERJoin ORDERS On CUSTOMER. Customer_ID = ORDERS. Customer_IDWhere 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, StateSelect Customer_Name, StateFrom CUSTOMERJoin ORDERS On CUSTOMER. Customer_ID = ORDERS. Customer_IDWhere 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 Sale2. Count of Items with a Sale3. Sum Of Units SoldQuestion 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).

top related