From ca469128df04a5887b56606176699888c260c842 Mon Sep 17 00:00:00 2001 From: zdj21jdz Date: Sun, 20 Oct 2019 23:47:24 -0400 Subject: [PATCH] Added extra question, addressed some formatting issues --- README.md | 57 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index c700aab..40acd68 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ :information_source:  This repository contains interview questions on various DevOps related topics -:bar_chart:  There are currently **300** questions +:bar_chart:  There are currently **312** questions :warning:  You don't need to know how to answer all the questions in this repo. DevOps is not about knowing all :) @@ -2017,6 +2017,7 @@ A short way of using if/else. An example: What does SQL stand for?
Structured Query Language +
@@ -2103,6 +2104,7 @@ Customer_ID | Customer_Name | Items_in_cart | Cash_spent_to_Date 100206 | Bobby Frank | 1 | 100.20 **ORDERS** + Customer_ID | Order_ID | Item | Price | Date_sold ------------ | ------------- | ------------- | ------------- | ------------- 100206 | A123 | Rubber Ducky | 2.20 | 2019-09-18 @@ -2117,38 +2119,30 @@ Customer_ID | Order_ID | Item | Price | Date_sold
How would I select all fields from this table?
-Select * +Select *
From Customers;
How many items are in John's cart?
-Select Items_in_cart -From Customers +Select Items_in_cart
+From Customers
Where Customer_Name = "John Smith";
What is the sum of all the cash spent across all customers?
-Select SUM(Cash_spent_to_Date) as SUM_CASH +Select SUM(Cash_spent_to_Date) as SUM_CASH
From Customers;
How many people have items in their cart?
-Select count(1) as Number_of_People_w_items -From Customers -where Items_in_cart > 0; -
- -
-How many people have items in their cart?
- -Select count(1) as Number_of_People_w_items -From Customers +Select count(1) as Number_of_People_w_items
+From Customers
where Items_in_cart > 0;
@@ -2159,9 +2153,42 @@ You would join them on the unique key. In this case, the unique key is Customer_ both the Customers table and Orders table
+
+How would you show which customer ordered which items?
+ +Select c.Customer_Name, o.Item
+From Customers c
+Left Join Orders o
+ On c.Customer_ID = o.Customer_ID; + +
+ #### Advanced +
+Using a with statement, how would you show who ordered cat food, and the total amount of money spent?
+ +with cat_food as (
+Select Customer_ID, SUM(Price) as TOTAL_PRICE
+From Orders
+Where Item like "%Cat Food%"
+Group by Customer_ID
+)
+Select Customer_name, TOTAL_PRICE
+From Customers c
+Inner JOIN cat_food f
+ ON c.Customer_ID = f.Customer_ID
+where c.Customer_ID in (Select Customer_ID from cat_food); + +Although this was a simple statement, the "with" clause really shines is when +a complex query needs to be run on a table before joining to another. With statements are nice, +because you create a pseudo temp when running your query, instead of creating a whole new table. + +The Sum of all the purchases of cat food weren't readily available, so we used a with statement to create +the pseudo table to retrieve the sum of the prices spent by each customer, then join the table normally. +
+ ## Scenarios Scenarios are questions which don't have verbal answer and require you one of the following: