Scratch Work
Scratch Work
Query to find Number of Customers that only Order at the Start of the Month: (Scratch
Work for Figure 10 in the Assignment)
/* This first piece of code is to find the consumers who have only ordered in the start of the mont
*/
WITH temp AS (SELECT
"Consumer ID",
count("day_Customer placed order datetime1") as NoOfOrders
FROM "Sample Data"
/* Sample Data is the name of the data set */
WHERE "Consumer ID" not in
(
SELECT "Consumer ID"
FROM "Sample Data"
WHERE "day_Customer placed order datetime1" > 5
)
GROUP BY "Consumer ID")
SELECT
s."Consumer ID" as 'Consumer ID',
t.NoOfOrders as 'Number of Orders',
MAX(s."day_Customer placed order datetime1") as 'Day of Last Order'
FROM "Sample Data" s
INNER JOIN temp t ON s."Consumer ID" = t."Consumer ID"
Where t.NoOfOrders > 2
/* The above where clause is just to select some of the highest ordering consumers */
GROUP BY 1,
2
Order By t.NoOfOrders DESC
Data Transformations:
Transformations to edit fields and add new fields into the table
1) Hour field extracted from Customer placed order datetime and converted into PST
Hour(add_hour( "Customer placed order datetime", -8))
Note: if clause is to handle cases where the times are across calendar days
3) Minutes Taken for Restaurant to Receive the Order created using logic as shown: