R
@Roopesh122
SQL Interview Q43
/*
Amazon SQL Interview Question
Find products which are exclusive to only Amazon and therefore not sold at Top Shop and Macy's.
Your output should include the product name, brand name, price, and rating.
Two products are considered equal if they have the same product name and same maximum retail price (mrp column).
*/
-- Schema Setup
SQL Interview Q42
/*
Uber SQL Interview Question
Uber wants to analyze driver performance by gives special diwali bonus!
Write SQL query to find top drivers based on the highest avg rating in each city
Make sure they have completed at least 5 rides in last 3 months
Note: Ignore incompleted rides (where end_time is missing)
SQL Interview Q41
/*
DBS Bank SQL Interview Question
You are given a table named sls_tbl that contains sales data for a specific product.
The table records the sales amount (sls_amt) for a product identified by pid on specific dates (sls_dt).
The sales data is recorded on a weekly basis, meaning that sales are expected to be recorded every 7 days.
Your task is to identify the missing weeks in the sales data.
Specifically, you need to find the dates on which sales data is expected but not recorded in the table
SQL Interview Q40
/*
Google SQL Interview Question
Find companies who have atleast 2 users who speks English and German both the languages
*/
-- Schema Setup
Create table company_users
(
company_id int,
SQL Interview Q39
/*
KPMG SQL Interview Question
You are given a table, support_, that stores information about employees, their office locations, email addresses, the floors they visit, and the resources they use.
Your task is to write an SQL query to generate a summary report for each unique name with the following details:
Total_Visit: The total number of entries (visits) for each name.
Most_Visited: The floor that the user has visited the most.
Resources_Used: A comma-separated list of distinct resources u
SQL Interview Q38
/*
Adobe SQL Interview Question
You have a table Tags with two columns, id and tag,
Each row in the Tags table contains an id and a tag. The tag column stores a string of hash (#) separated numbers, where each number represents a different tag.
For example, a tag value of 200#100#300 means the tags 200, 100, and 300 are associated with the given id.
Your task is to process the Tags table to generate a report that shows the count of each unique tag value (value) for each id.
The output should
SQL Interview Q37
/*
Zomato SQL Interview Question
Write a SQL query to find the top 2 restaurants in each city with the highest average rating.
The output should include the following columns:
city_id, city_name, restaurant id, restaurant_name and avg_rating
*/
-- Schema Setup
CREATE TABLE cities (
SQL Interview Q36
/*
Deloitte SQL Interview Question
Write a SQL query that transforms the data into a specific format. The output should display the names sorted alphabetically and organized under their corresponding occupations in separate columns.
Each row in the output should represent a unique position in the sorted list, and if there are fewer names for a particular occupation, the remaining cells should be filled with NULL.
*/
-- Schema Setup
CREATE TABLE occupation (
name VARCHAR(20),
SQL Interview Q35
/*
You are given a dataset containing employee information, including their employee_id, employee_name, age, department, and salary.
Generate a summary report that includes the following details for each department:
- Number of Employees: The total count of employees working in each department.
- Employee Info: A concatenated string of employee names and their corresponding ages, separated by a specific delimiter.
The output should be structured in a table format with the following columns:
SQL Interview Q34
/*
Swiggy SQL Interview Question
Find the customers who bought a product for atleast three consecutive days
*/
-- Schema Setup
CREATE TABLE purchases (
empid INT,
purchase_date DATE
SQL Interview Q33
/*
Cisco SQL Interview Question
Convert the first letter of each word found in content_text to uppercase, while keeping the rest of the letters lowercase.
Your output should include the original text in one column and the modified text in another column.
*/
-- Schema Setup
CREATE TABLE user_content (content_id INT PRIMARY KEY,customer_id INT,content_type VARCHAR(50),content_text VARCHAR(255));
SQL Interview Q31
/*
Microsoft SQL Interview Question
Find the total number of downloads for paying and non-paying users by date.
Include only records where non-paying customers have more downloads than paying customers.
The output should be sorted by earliest date first and contain 3 columns date, non-paying downloads, paying downloads.
*/
-- Schema Setup
CREATE TABLE ms_user_dimension (user_id INT PRIMARY KEY,acc_id INT);
SQL Interview Q32
/*
Amazon SQL Interview Question
Identify continuous periods of a specific service status (down) from the service_log table,
where the downtime lasts for 5 or more consecutive records, and summarize the start and end times for these periods.
*/
-- Schema Setup
CREATE TABLE service_log (
service_name VARCHAR(50),
SQL Interview Q30
/*
Uber SQL Interview Question
Write a query to find the cancellation rate of requests with unbanned users(both drivers and clients must not be banned ) each day between '2023-10-01' And '2023-10-03'
Cancellation rate is computed by dividing the number of cancelled requests (by client or driver) requests with unbanned users by the total number of requests with unbanned users on that day
*/
-- Schema Setup
CREATE TABLE trips (
SQL Interview Q29
/*
Apple SQL Interview Question
Find the number of Apple product users and the number of total users with a device and group the counts by language
Assume Apple products are only MacBook-Pro, iPhone 5s, and iPad-air.
Output the language along with the total number of Apple users and users with any device.
Order your results based on the number of total users in descending order.
*/
-- Schema Setup
SQL Interview Q28
/*
Walmart SQL Interview Question
Identify users who started a session and placed an order on the same day.
For these users, calculate the total number of orders and the total order value for that day.
Your output should include the user, the session date, the total number of orders, and the total order value for that day.
*/
-- Schema Setup
CREATE TABLE sessions(session_id INT PRIMARY KEY,user_id INT,session_date DATETIME);
SQL Interview Q27
/*
PayPal SQL Interview Question
The table contains sales data for different individuals across various categories (Electronics, Clothing, Grocery) for specific months.
Write a sql query to create a pivot table that shows the month-wise total sales for each category
*/
-- Schema Setup
CREATE TABLE sales_data (
name VARCHAR(20),
SQL Interview Q26
/*
JP Morgan, Chase, Bloomberg SQL Interview Question
Bank of Ireland has requested that you detect invalid transactions in December 2022.
An invalid transaction is one that occurs outside of the bank's normal business hours.
The following are the hours of operation for all branches:
Monday - Friday 09:00 - 16:00
Saturday & Sunday Closed
Irish Public Holidays 25th and 26th December
SQL Interview Q25
/*
Amazon Interview Question
Find Customers who placed more than 50% of their Orders in the Last Month
*/
-- Schema Setup
CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
CustomerID VARCHAR(10),
SQL Interview Q24
/*
Google SQL Interview Question
Find all records from days when the number of distinct users receiving emails was greater than the number of distinct users sending emails.
*/
-- Schema Setup
CREATE TABLE google_gmail_emails (id INT PRIMARY KEY,from_user VARCHAR(50),to_user VARCHAR(50),day INT);
INSERT INTO google_gmail_emails (id, from_user, to_user, day) VALUES(0, '6edf0be4b2267df1fa', '75d295377a46f83236', 10),(1, '6edf0be4b2267df1fa', '32ded68d89443e808', 6),(2, '6edf0be4b2267df1fa', '55