0% found this document useful (0 votes)
3 views

SQL Test - Back Market

The document contains two SQL queries: the first identifies customers with repeated failed payments by counting instances of payment failures, while the second highlights the top five merchants by sales in each country. The first query uses a common table expression (CTE) to filter customers with two or more failed payments, and the second CTE calculates total sales per merchant before ranking them. Both queries utilize aggregation and ranking functions to present the required data.

Uploaded by

owl30417
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

SQL Test - Back Market

The document contains two SQL queries: the first identifies customers with repeated failed payments by counting instances of payment failures, while the second highlights the top five merchants by sales in each country. The first query uses a common table expression (CTE) to filter customers with two or more failed payments, and the second CTE calculates total sales per merchant before ranking them. Both queries utilize aggregation and ranking functions to present the required data.

Uploaded by

owl30417
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Candidate: Hendrick Lin

Date: 2024/02/17

1. Write an SQL query which highlights customers who failed repeatedly.

WITH Failed_Payments AS (
SELECT
p.CLIENT_ID_ANONYMIZED,
COUNT(*) AS Total_Failed_Payments

FROM PAYMENT p
WHERE p.STATE = 0
GROUP BY 1
HAVING COUNT(*) >= 2 --Definition of "repeatedly" is adjustable
)

SELECT
fp.CLIENT_ID_ANONYMIZED,
fp.Total_Failed_Payments

FROM Failed_Payments fp
ORDER BY 2 DESC;

2. Write an SQL query which highlights the top 5 merchants with the biggest sales (in €) per
country.

With Top_Merchant_By_Country AS (
SELECT
OL.MERCHANT_ID_ANONYMIZED,
M.COUNTRY_CODE,
SUM(OL.PRICE * OL.QUANTITY) AS Total_Sales
FROM
ORDERLINE OL
JOIN MERCHANT M ON OL.MERCHANT_ID_ANONYMIZED =
M.MERCHANT_ID_ANONYMIZED
GROUP BY 1, 2
ORDER BY 2, 3 DESC
)

SELECT
*
FROM (
SELECT
*,
RANK() OVER(PARTITION BY COUNTRY_CODE ORDER BY total_sales DESC) AS ranking

FROM Top_Merchant_By_Country
) ranked

WHERE ranking <= 5;

You might also like