50 SQL To Python Series Problems
50 SQL To Python Series Problems
Deepanshu
SQL to Python Series
Problem 1/50
SQL Solution
SQL to Python Series
Problem 1/50
Key Points:
1. Used WHERE clause with AND to filter
data.
2. SQL use of 𝘁𝗵𝗿𝗲𝗲-𝘃𝗮𝗹𝘂𝗲𝗱 𝗹𝗼𝗴𝗶𝗰 where
expressions can evaluate to TRUE,
FALSE, or UNKNOWN.
3. 𝗪𝗛𝗘𝗥𝗘 𝗰𝗹𝗮𝘂𝘀𝗲, only rows where the
expression is TRUE are returned.
4. Order of predicates evaluation is not
guaranteed. For detail explanation click
here.
SQL Solution
SQL to Python Series
Problem 1/50
Python Solution
SQL to Python Series
Problem 1/50
Key Points:
1. Used Boolean Indexing clause with
Boolean operator & to filter data.
2. Pandas does not use of 𝘁𝗵𝗿𝗲𝗲-𝘃𝗮𝗹𝘂𝗲𝗱
𝗹𝗼𝗴𝗶𝗰.
3. For fetching column used fancy indexing
df[[`col1`]] to return DataFrame object.
Simply using df[`col1`] will return series
object.
Python Solution
SQL to Python Series
Problem 2/50
SQL Solution
SQL to Python Series
Problem 2/50
Key Points:
1. Used WHERE clause with OR to filter data.
2. SQL use of 𝘁𝗵𝗿𝗲𝗲-𝘃𝗮𝗹𝘂𝗲𝗱 𝗹𝗼𝗴𝗶𝗰 where
expressions can evaluate to TRUE, FALSE,
or UNKNOWN.
3. Rows having referee_id null will return
unknown by predicate referee_id<>2 and
will not be shown in output if we do not
include OR referee_id is null.
4. 𝗪𝗛𝗘𝗥𝗘 𝗰𝗹𝗮𝘂𝘀𝗲, only rows where the
expression is TRUE are returned.
SQL Solution
SQL to Python Series
Problem 2/50
Python Solution
SQL to Python Series
Problem 2/50
Key Points:
1. Used Boolean Indexing clause with
Boolean operator & to filter data.
2. Used Fancy indexing to fetch DataFrame
with requested column.
Python Solution
SQL to Python Series
Problem 3/50
SQL Solution
SQL to Python Series
Problem 3/50
Python Solution
SQL to Python Series
Problem 4/50
SQL Solution
SQL to Python Series
Problem 4/50
Python Solution
SQL to Python Series
Problem 5/50
SQL Solution
SQL to Python Series
Problem 5/50
Python Solution
SQL to Python Series
Problem 6/50
SQL Solution
SQL to Python Series
Problem 6/50
Python Solution
SQL to Python Series
Problem 7/50
SQL Solution
SQL to Python Series
Problem 7/50
Python Solution
SQL to Python Series
Problem 8/50
SQL Solution
SQL to Python Series
Problem 8/50
Python Solution
SQL to Python Series
Problem 9/50
SQL Solution
SQL to Python Series
Problem 9/50
Python Solution
SQL to Python Series
Problem 10/50
SQL Solution
SQL to Python Series
Problem 11/50
Write a solution to
find the number of
times each
student attended
each exam.
SQL Solution
SQL to Python Series
Problem 12/50
SQL Solution
SQL to Python Series
Problem 14/50
Python Solution
SQL to Python Series
Problem 15/50
SQL Solution
SQL to Python Series
Problem 15/50
Python Solution
SQL to Python Series
Problem 16/50
SQL Solution
SQL to Python Series
Problem 16/50
Python Solution
SQL to Python Series
Problem 17/50
SQL Solution
SQL to Python Series
Problem 17/50
Python Solution
SQL to Python Series
Problem 18/50
Python Solution
SQL to Python Series
Problem 19/50
SQL Solution
SQL to Python Series
Problem 19/50
Python Solution
SQL to Python Series
Problem 20/50
Write an SQL query to find for each month and country, the
number of transactions and their total amount, the number of
approved transactions and their total amount.
SQL Solution
SQL to Python Series
Problem 20/50
If the customer's preferred delivery date is the same as the order date,
then the order is called immediate; otherwise, it is called scheduled.
The first order of a customer is the order with the earliest order date that
the customer made. It is guaranteed that a customer has precisely one
first order.
SQL Solution
SQL to Python Series
Problem 21/50
Python Solution
SQL to Python Series
Problem 22/50
In other words, you need to count the number of players that logged in
for at least two consecutive days starting from their first login date,
then divide that number by the total number of players.
Click here to try
SQL to Python Series
Problem 22/50
SQL Solution
SQL to Python Series
Problem 22/50
SQL Solution
SQL to Python Series
Problem 23/50
Python Solution
SQL to Python Series
Problem 24/50
SQL Solution
SQL to Python Series
Problem 24/50
SQL Solution
SQL to Python Series
Problem 25/50
SQL Solution
SQL to Python Series
Problem 26/50
SQL Solution
SQL to Python Series
Problem 27/50
Python Solution
SQL to Python Series
Problem 28/50
Write a solution
to find the
largest number
that appears
only once in the
table.
If there is no
single number,
return null.
SQL Solution
SQL to Python Series
Problem 28/50
Python Solution
SQL to Python Series
Problem 29/50
Write a solution to
report the customer ids
from the Customer table
that bought all the
products in the Product
table.
Click here to try
SQL to Python Series
Problem 29/50
SQL Solution
SQL to Python Series
Problem 29/50
Python Solution
SQL to Python Series
Problem 30/50
SQL Solution
SQL to Python Series
Problem 30/50
Python Solution
SQL to Python Series
Problem 31/50
SQL Solution
SQL to Python Series
Problem 31/50
Python Solution
SQL to Python Series
Problem 31/50
Python Solution
SQL to Python Series
Problem 32/50
SQL Solution
SQL to Python Series
Problem 32/50
Python Solution
SQL to Python Series
Problem 33/50
SQL Solution
SQL to Python Series
Problem 33/50
Python Solution
SQL to Python Series
Problem 34/50
SQL Solution
SQL to Python Series
Problem 34/50
Python Solution
SQL to Python Series
Problem 35/50
SQL Solution
SQL to Python Series
Problem 35/50
Python Solution
SQL to Python Series
Problem 36/50
The salary categories are:
SQL Solution
SQL to Python Series
Problem 36/50
Python Solution
SQL to Python Series
Problem 37/50
SQL Solution
SQL to Python Series
Problem 37/50
Python Solution
SQL to Python Series
Problem 38/50
Seat Table: Contains the ID and name of each student. The IDs
are continuous increments.
Swap the seat IDs for every pair of consecutive students. If
there’s an odd number of students, the last student’s ID
remains unchanged.
Return the result table ordered by ID in ascending order.
Click here to try
SQL to Python Series
Problem 38/50
SQL Solution
SQL to Python Series
Problem 38/50
SQL Solution
SQL to Python Series
Problem 38/50
Python Solution
SQL to Python Series
Problem 39/50
SQL Solution
SQL to Python Series
Problem 39/50
Python Solution
Alternate using pd.concat()
SQL to Python Series
Problem 40/50
Calculate the 7-day moving sum and the moving average of the
amount. The moving average should be rounded to two decimal
places.
Return the result table ordered by visited_on in ascending order.
SQL to Python Series
Problem 40/50
SQL Solution
SQL to Python Series
Problem 40/50
Python Solution
SQL to Python Series
Problem 41/50
SQL Solution
SQL to Python Series
Problem 41/50
Python Solution
SQL to Python Series
Problem 42/50
SQL Solution
SQL to Python Series
Problem 42/50
Python Solution
SQL to Python Series
Problem 43/50
SQL Solution
SQL to Python Series
Problem 43/50
Python Solution
SQL to Python Series
Problem 44/50
SQL Solution
SQL to Python Series
Problem 44/50
SQL Solution
SQL to Python Series
Problem 44/50
Python Solution
SQL to Python Series
Problem 45/50
SQL Solution
SQL to Python Series
Problem 45/50
SQL Solution
SQL to Python Series
Problem 45/50
Python Solution
SQL to Python Series
Problem 46/50
SQL Solution
SQL to Python Series
Problem 46/50
Python Solution
SQL to Python Series
Problem 47/50
SQL Solution
SQL to Python Series
Problem 47/50
Python Solution
SQL to Python Series
Problem 48/50
SQL Solution
SQL to Python Series
Problem 48/50
Python Solution
SQL to Python Series
Problem 49/50
SQL Solution
SQL to Python Series
Problem 49/50
Python Solution
SQL to Python Series
Problem 50/50
SQL Solution
SQL to Python Series
Problem 50/50
Python Solution