Challenge SQL

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

To begin with the exercises, please click on

https://www.db-fiddle.com/f/gNRV8Tcbx9LrcxQWngLZRt/2

In that link you will see a database with two tables, this is how it works,
you write your query on the right window of the site, and you click on "play", once you have
the result you want,
you need to copy the link that was generated when running the query, and that's the first
link,
then you can erase that query and write another one, once you get the result, you copy the
link, and
so on.

Now, we will start with this:

You have a sales table and a users table


we need to create a query that shows us the following

Customer Type- that can show two values: "Nuevo" y "Recurrente"


A user is new during the whole month of his first purchase, no matter when he made it,
a user is recurrent every month after the month of his first purchase.

Ejercicio 1. The table you should obtain is like this

Customer Type mes 11 mes 12 mes 01


new cuenta cuenta cuenta
recurrent cuenta cuenta cuenta

cuenta reffers to the count of users new and recurrent for every month.

Ejercicio 2
Next we need to add the store to the previous table, so that we can see something like this:

Store customer type mes 11 mes 12 mes 01


SR new cuenta
SR recurrent cuenta
DV
DV
SF
SF
QR
QR
Total new
Tota recurrent
Ejercicio 3

For any given day, selected on a filter "and created="2021-01-13", for example, we need to
see the coupons spend amount of that day,
for new and recurrent users, then by store.
And the same for the same period of time of last month, and a Period over Period column
that shows the variation like de table in the example.

And the same but for the accumulated days of the month, like if you are selecting 2021-01-
13, you should show the accum spend of that month,
and the same for the past month, and the variation.

Ejercicio 4

As we stated before, there are clients that are activated, the month their first PO is maden,
I need a table that calls the first month they purchased, no matter what that is, the month 0,
and then, the next month and, the next, how many unique users bought again.

For example

10 sujetos compraron por primera vez(la primera vez que aparezca en la tabla) en
noviembre, en diciembre, de esos 10, sólo compraron 4 y en enero, de esos 10, sólo
compraron 5 es una cuenta, no importa quienes son, si no que compraron, se cuentan sólo
una vez aunque hayan comprado 1, 2 o 500 veces en un mes, sólo aparecerán contados
como 1.

10 people bought for the first time in november, then in december, of those 10, only 4 out of
those 10 bought again, and in january, only 5, that is a count, no matter who they are, they
are counted only once in the month, even if they made more than 1 purchase.

the resulting table should be like the one below, the month called "cohort", is the month
where they bought for the first time and is also the month 0.
Note: You gotta use the version of Mysql that is already in the fiddle (first link sent)
and you should not use create, drop, alter, sentences.

You might also like