0% found this document useful (0 votes)
133 views2 pages

ShopDeck BA Assignment by Nishant

The document contains SQL queries to analyze customer orders data. The queries include getting daily new and repeat customer counts, customers who placed their third order, orders from specific customers including their referral code, and daily order counts and percentages by seller.

Uploaded by

qnishant3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views2 pages

ShopDeck BA Assignment by Nishant

The document contains SQL queries to analyze customer orders data. The queries include getting daily new and repeat customer counts, customers who placed their third order, orders from specific customers including their referral code, and daily order counts and percentages by seller.

Uploaded by

qnishant3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

- Daily new customers (who placed their first order)

SELECT
DATE(Order_time) AS OrderDate,
COUNT(DISTINCT u.User_Id) AS NewCustomerCount
FROM
Order AS o
JOIN
User AS u
ON
o.Customer_id = u.User_Id
WHERE
o.Order_Id = (SELECT MIN(Order_Id) FROM Order WHERE Customer_id =
o.Customer_id)
GROUP BY
OrderDate;

- Daily old customers (who placed their repeat orders)

SELECT
DATE(Order_time) AS OrderDate,
COUNT(DISTINCT u.User_Id) AS OldCustomerCount
FROM
Order AS o
JOIN
User AS u
ON
o.Customer_id = u.User_Id
WHERE
o.Order_Id != (SELECT MIN(Order_Id) FROM Order WHERE Customer_id =
o.Customer_id)
GROUP BY
OrderDate;

- Daily customers who have placed their 3rd lifetime order

SELECT
DATE(Order_time) AS OrderDate,
COUNT(DISTINCT u.User_Id) AS ThreeTimeCustomerCount
FROM
Order AS o
JOIN
User AS u
ON
o.Customer_id = u.User_Id
GROUP BY
OrderDate
HAVING
COUNT(DISTINCT o.Order_Id) >= 3;

2.

SELECT
o.Order_Id,
o.Order_time,
u.First_Name AS Customer_Name,
u.Referral_Code
FROM
Orders AS o
JOIN
User AS u
ON
o.Customer_id = u.User_Id
WHERE
u.First_Name IN ('Vidhisha', 'Ranu', 'Jhanvi')
AND u.Referral_Code IS NOT NULL;

3.

SELECT
DATE(Order_time) AS OrderDate,
Seller_Name,
(COUNT(Order_Id) / (SELECT COUNT(*) FROM Orders WHERE DATE(Order_time) =
OrderDate)) * 100 AS ContributionPercentage
FROM
Orders
GROUP BY
OrderDate, Seller_Name;

You might also like