R

@Roopesh122

SQL Interview Q23

MySQL
1 year ago
/* A company wants to divide the employees into teams such that all the member on each team have the salary. The teams should follow thses criteria: a) Each team should consist of at least two employees. b) All the employees on a team should have the same salary c) If the salary of an employee is unique, we do not assign this employee to any team. */ -- Schema Setup create table company(

SQL Interview Q22

MySQL
1 year ago
/* Expedia, Airbnb SQL Interview Question Find the number of rows for each review score earned by 'Hotel Arena'. Output the hotel name (which should be 'Hotel Arena'), review score along with the corresponding number of rows with that score for the specified hotel. */ -- Schema Setup CREATE TABLE hotel_reviews (hotel_address VARCHAR(255),additional_number_of_scoring INT,review_date DATETIME,average_score FLOAT,hotel_name VARCHAR(100),reviewer_nationality VARCHAR(100),negative_review TEXT,revi

SQL Interview Q21

MySQL
1 year ago
/* LinkedIn, Dropbox SQL Interview Question Write a query that calculates the difference between the highest salaries found in the marketing and engineering departments. Output just the absolute difference in salaries. */ -- Schema Setup CREATE TABLE db_employee (id INT,first_name VARCHAR(50),last_name VARCHAR(50),salary INT,department_id INT); INSERT INTO db_employee (id, first_name, last_name, salary, department_id) VALUES(10306, 'Ashley', 'Li', 28516, 4),(10307, 'Joseph', 'Solomon', 19945

SQL Interview Q20

MySQL
1 year ago
/* Tesla SQL Interview Question You are given a table of product launches by company by year. Write a query to count the net difference between the number of products companies launched in 2020 with the number of products companies launched in the previous year. Output the name of the companies and a net difference of net products released for 2020 compared to the previous year. */ -- Schema Setup CREATE TABLE car_launches(year int, company_name varchar(15), product_name varchar(30));

SQL Interview Q19

MySQL
1 year ago
/* IBM SQL Interview Question IBM is working on a new feature to analyze user purchasing behavior for all Fridays in the first quarter of the year. For each Friday separately, calculate the average amount users have spent per order. The output should contain the week number of that Friday and average amount spent. */ -- Schema Setup CREATE TABLE user_purchases(user_id int, date date, amount_spent float, day_name varchar(15));

SQL Interview Q18

MySQL
1 year ago
/* Airbnb SQL Interview Question Find the total number of available beds per hosts' nationality. Output the nationality along with the corresponding total number of available beds. Sort records by the total available beds in descending order. */ -- Schema Setup CREATE TABLE airbnb_apartments(host_id int,apartment_id varchar(5),apartment_type varchar(10),n_beds int,n_bedrooms int,country varchar(20),city varchar(20));

SQL Interview Q17

MySQL
1 year ago
/* Microsoft SQL Interview Question Given a list of projects and employees mapped to each project, calculate by the amount of project budget allocated to each employee. The output should include the project title and the project budget rounded to the closest integer. Order your list by projects with the highest budget per employee first. */ -- Schema Setup CREATE TABLE ms_projects(id int, title varchar(15), budget int); INSERT INTO ms_projects VALUES (1, 'Project1', 29498),(2, 'Project2', 3

SQL Interview Q16

MySQL
1 year ago
/* Uber SQL Interview Question Some forecasting methods are extremely simple and surprisingly effective. Naïve forecast is one of them. To create a naïve forecast for "distance per dollar" (defined as distance_to_travel/monetary_cost), first sum the "distance to travel" and "monetary cost" values monthly. This gives the actual value for the current month. For the forecasted value, use the previous month's value. After obtaining both actual and forecasted values, calculate the root mean squared

SQL Interview Q15

MySQL
1 year ago
/* Google SQL Interview Question You are analyzing a social network dataset at Google. Your task is to find mutual friends between two users, Karl and Hans. There is only one user named Karl and one named Hans in the dataset. The output should contain 'user_id' and 'user_name' columns. */ -- Schema Setup

SQL Interview Q14

MySQL
1 year ago
/* Amazon SQL Interview Question Given a table 'sf_transactions' that records purchase transactions by date, calculate the month-over-month percentage change in revenue The output should include the year-month in YYYY-MM format and the percentage change in revenue rounded to two decimal places, sorted chronologically from the start to the end of the year The percentage change will be calculated from the second month onward using the formula ((Current Month's Revenue - Previous Month's Revenue

SQL Interview Q13

SQL
1 year ago
/* Meta/Facebook SQL Interview Question The "famous" table contains two columns: user_id and follower_id. It represents the follower relationships among users, where each follower_id is also a user on the platform. Calculate the famous percentage for each user using the formula: Famous Percentage = (Number of followers a user has) / (Total number of users on the platform) */

SQL Interview Q12

MySQL
1 year ago
/* Walmart SQL Interview Question Write an SQL query to find the projects with the highest budget-per-employee ratio using the two related tables projects and employees. */ -- Schema Setup CREATE TABLE Projects ( ProjectID INT PRIMARY KEY,

SQL Interview Q11

MySQL
1 year ago
/* Nvidia, Microsoft SQL Interview Question Find the number of transactions that occurred for each product. Output the product name along with the corresponding number of transactions and order records by the product id in ascending order. You can ignore products without transactions. */ -- Schema Setup CREATE TABLE excel_sql_inventory_data (product_id INT,product_name VARCHAR(50),product_type VARCHAR(50),unit VARCHAR(20),price_unit FLOAT,wholesale FLOAT,current_inventory INT);

SQL Interview Q9

MySQL
1 year ago
/* Amazon SQL Interview Question Write a query that'll identify returning active users. A returning active user is a user that has made a second purchase within 7 days of any other of their purchases. Output a list of user_ids of these returning active users. */ -- Schema setup

SQL Interview Q10

MySQL
1 year ago
/* Microsoft SQL Interview Question Write an SQL query to find the number of employees who received a bonus and those who did not. Since the employee table's bonus values are corrupted, you should use the bonus table to determine if an employee received a bonus. Note that an employee can receive more than one bonus. The output should include a column has_bonus (1 if they received a bonus, 0 if not) along with the corresponding number of employees for each category. */ -- Schema setup CREATE

SQL Interview Q7

MySQL
1 year ago
/* Netflix SQL Interview Question You have been given the following tables schema: `nominee_information` Table | Column | Data Type | Description | |-----------------|-------------|---------------------------------------------------| | `name` | VARCHAR(20) | The name of the nominee | | `amg_person_id` | VARCHAR(10) | A unique identifier for the nominee |

SQL Interview Q8

MySQL
1 year ago
/* Pwc SQL Interview Question Task: Calculate the factorial of a given number using a recursive CTE */ -- Setting the number for which factorial is needed SET @final_factorial = 6;

SQL INTERVIEW Q6

MySQL
1 year ago
/* Google SQL Interview Question You are given a transaction table, which records transactions between sellers and buyers. The structure of the table is as follows: | Column | Data Type | Description | |----------------|-----------|-------------------------------| | Transaction_ID | INT | Unique transaction identifier | | Customer_ID | INT | Unique customer identifier |

SQL Interview Q5

MySQL
1 year ago
/* Amazon SQL Interview Question You are given an Employee table with the following schema: | Column | DataType | Description | |----------|----------|------------------------------------------| | id | INT | Unique identifier for each employee. | | name | VARCHAR | Employee's name. | | sex | CHAR | Gender: 'M' for Male, 'F' for Female. |

SQL Interview Q4

MySQL
1 year ago
/* EY SQL Interview Question You have a table named ATTENDANCE that records employees' daily attendance, indicating whether they were absent or present on each day The table structure is as follows: | Column Name | Data Type | |--------------|-----------| | `EMPLOYEE` | VARCHAR | | `DATES` | INT |