100% found this document useful (1 vote)
24 views8 pages

SQL Queries for Data Analysis Skills

The document contains 5 interview questions related to data analysis skills. Each question provides a scenario and asks the candidate to write a SQL query to analyze data and return specific information. The questions cover skills like filtering data, calculating metrics, aggregating data over time, and joining multiple tables.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
24 views8 pages

SQL Queries for Data Analysis Skills

The document contains 5 interview questions related to data analysis skills. Each question provides a scenario and asks the candidate to write a SQL query to analyze data and return specific information. The questions cover skills like filtering data, calculating metrics, aggregating data over time, and joining multiple tables.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

INTERVIEW QUESTION

This Photo by Unknown Author is licensed under


CC BY-SA
Question 1: DATA ANALYST SKILLS
 Given a table of candidates and their skills, you're tasked with finding the candidates best suited
for an open Data Analyst job. You want to find candidates who are proficient in Python, Tableau,
and SQL.
 Write a query to list the candidates who possess all of the required skills for the job. Sort the the
output by candidate ID in ascending order.
 Assumption:
• There are no duplicates in the candidates table.
Question 2 : FINAL ACCOUNT BALANCE
 Given a table of bank deposits and withdrawals,
 Return the final balance for each account.
 Assumption:
 All the transactions performed for each account are present in the table; no transactions are
missing.
Question 3:App Click-through Rate (CTR)
 Assume you have an events table on app analytics.
 Write a query to get the app’s click-through rate (CTR %) in 2022.
 Output the results in percentages rounded to 2 decimal places.
 Notes:
 To avoid integer division, you should multiply the click-through rate by 100.0, not 100.
 Percentage of click-through rate = 100.0 * Number of clicks / Number of impressions
Question 4: Spotify Streaming History
 You're given two tables on Spotify users' streaming data. songs_history table contains the historical
streaming data and songs_weekly table contains the current week's streaming data.
 Write a query to output the user id, song id, and cumulative count of song plays as of 4 August 2022
sorted in descending order.
 Definitions:
 song_weekly table currently holds data from 1 August 2022 to 7 August 2022.
 songs_history table currently holds data up to to 31 July 2022.
 The output should include the historical data in this table.
 Assumption: There may be a new user or song in the songs_weekly table not present in the
songs_history table.
Question 4: Spotify Streaming History
Question 5: Monthly Merchant Balance
 Say you have access to all the transactions for a given merchant account.
 Write a query to print the cumulative balance of the merchant account at the end of each day, with the
total balance reset back to zero at the end of the month.
 Output the transaction date and cumulative balance.
This Photo by Unknown Author is licensed under CC BY-SA-NC

Common questions

Powered by AI

To find candidates proficient in Python, Tableau, and SQL, you should execute a SQL query checking for all three skills in each candidate's record. The query would join or filter through a 'skills' table where each candidate's skills are listed. Here's a basic structure of the query: SELECT candidate_id FROM candidates WHERE skills LIKE '%Python%' AND skills LIKE '%Tableau%' AND skills LIKE '%SQL%' ORDER BY candidate_id ASC. This query assumes a candidate's skills are stored in a delimited string format in a column within the same candidate table.

To calculate the CTR, you start by filtering the events from the year 2022. Subsequently, compute the number of clicks and impressions during this period. Use the formula CTR = 100.0 * SUM(clicks) / SUM(impressions) to ensure decimal precision. The SQL query would be something like: SELECT ROUND(100.0 * SUM(clicks) / SUM(impressions), 2) AS CTR_percentage FROM events WHERE event_date BETWEEN '2022-01-01' AND '2022-12-31'. Ensuring the use of 100.0 prevents integer division from occurring .

To combine historical and current week's data from two tables, join both tables using UNION to incorporate all possible records. Summate the play counts while grouping by user_id and song_id. Sort these results to get cumulative play counts: SELECT user_id, song_id, SUM(play_count) AS cumulative_plays FROM (SELECT user_id, song_id, play_count FROM songs_history WHERE date <= '2022-07-31' UNION ALL SELECT user_id, song_id, play_count FROM songs_weekly WHERE date <= '2022-08-04') temp GROUP BY user_id, song_id ORDER BY cumulative_plays DESC .

Start by calculating the daily cumulative balance for each merchant account. Accumulate daily transactions using an aggregate function and reset at month-end: SELECT transaction_date, SUM(amount) OVER (PARTITION BY EXTRACT(YEAR FROM transaction_date), EXTRACT(MONTH FROM transaction_date) ORDER BY transaction_date) as cumulative_balance FROM transactions. Ensure your result resets at the change of each month by using a window partition based on month and year .

To calculate the final balance for each account, the operation must summate all deposits and withdrawals. Using SQL, you can group by account identifier and calculate the sum of deposits minus the sum of withdrawals: SELECT account_id, SUM(deposits) - SUM(withdrawals) AS final_balance FROM transactions GROUP BY account_id. This computes the net of deposits and withdrawals assuming deposits and withdrawals are in separate columns within the same table .

You might also like