Vaishali SQL Assessment
Vaishali SQL Assessment
INSTEAD DOWNLOAD THIS DOCUMENT TO YOUR LOCAL SYSTEM and RECORD YOUR RESPONSES IN THAT FILE.
Q1) From the table above, find employees with their department names.
FROM Employees e
JOIN Departments d
ON e.DepartmentID = d. DepartmentID;
Q2) From the table above, list all employees, including those without a department.
Ans - SELECT e.EmployeeID, e.Name, d.DepartmentName
FROM Employees e
ON e.DepartmentID = d.DepartmentID;
Q3) From the table above, list all employees and departments, showing matches where possible.
Ans -
FROM Employees e
UNION
FROM Employees e
FROM Employees e
Q5) From the table above, Find pairs of employees with the same department.
FROM Employees e1
JOIN Employees e2
ON e1.DepartmentID = e2.DepartmentID
Ans -
FROM Employees e
“2024-12-01
2024-12- 02
2024-12-03"
Write SQL queries (CREATE, INSERT, & SELECT, etc) to generate all possible combinations.
Ans ----
PROCESSOR_NAME VARCHAR(50));
RAM_SIZE VARCHAR(20));
STORAGE_SIZE VARCHAR(20));
-- INSERT INTO Processors (PROCESSORID, PROCESSOR_NAME) VALUES (1, 'Intel i5'), (2, 'Intel i7'), (3, 'AMD Ryzen 5');
-- RAM INSERT INTO RAM (RAMID, RAM_SIZE) VALUES (1, '8GB'), (2, '16GB');
--INSERT INTO STORAGE (STORAGEID, STORAGE_SIZE) VALUES (1, '256 GB SSD'), (2, '512 GB SSD'), (3, '1 TB SSD');
SELECT P.PROCESSOR_NAME, R.RAM_SIZE, S.STORAGE_SIZE FROM PROCESSORS P CROSS JOIN RAM R CROSS JOIN STORAGE S;
Q9) Write SQL queries (CREATE, INSERT, SELECT), A retailer wants to identify combinations of products and stores where a product isn’t
available.
ANS ----
-- INSERT INTO PRODUCTS (PRODUCT_ID, PRODUCT_NAME) VALUES ('ax890000869', 'LAPTOP'), ('py562MM220', 'TABLET'), ('00005233kh',
'SMARTPHONE');
-- INSERT INTO STORES (STORE_ID, STORE_NAME) VALUES (1, 'STOREXYZ'), (2, 'STOREABX');
-- INSERT INTO INVENTORY (PRODUCT_ID, STORE_ID) VALUES ('ax890000869', 1), ('py562MM220', 2), ('00005233kh', 1), ('00005233kh', 2);
FROM PRODUCTS p
Q10) Write a query to pair every product with every other product to analyze cross-sales opportunities.
SELECT p1.PRODUCT_NAME AS Product1, p2.PRODUCT_NAME AS Product2
FROM PRODUCTS p1
Q1) Based on the below reporting hierarchy, find their managers for each employee in an organization and the output to be as follows:
ANS--
SELECT
;
Q2) Calculate a running total of sales for each product by date as per the below data
Ans ----
OVER (
PARTITION BY ProductID
ORDER BY SaleDate
) AS RunningTotal
FROM Sales
Customer
CUSTOMERID FULL_NAME
1 Alice Johnson
2 Bob Smith
3 Charlie Brown
Q2) Find Contacts with phone numbers not in the format of (XXX) XXX-XXXX
CONTACTS
CONTACTID PHONE_NUMBER
1 (123) 456-7890
2 1234567890
3 (987) 654-3210
Q3) Write a SQL query to convert email addresses to lowercase and remove spaces
EMAILs
EMAIL_ID EMAIL_ADDRESS
1 User@Examp le.com
2 [email protected]
Q5) Write a query to find the missing dates from the below table.
Q6) Write a SQL query to round a set of prices to the nearest dollar and truncate to two decimals.
Q7) Write a SQL query to compute the standard deviation and variance for a set of sales based on the table below:
Anss --- forgot the syntax
Q8) Write a SQL query to calculate rank and percentile ranks for the students below based on their scores.
Anss ---select Student_ID, Score, rank() over (order by Score desc) as RANK,
from STUDENTS;
Q9) Write a SQL query to extract the domain name from email addresses.
Q10) Write a SQL query to extract numeric values from mixed alphanumeric strings.
Q11) Extract first 3 characters from the below given product code
Q1) Calculate total sales for each region, but group "East" and "West" into "Domestic" and others into "International."
Ans ---
SELECT
CASE
ELSE 'International'
END AS RegionGroup,
SUM(AMOUNT) AS TotalSales
FROM SALES
GROUP BY RegionGroup;
Q2) Assign grades based on student scores as per the below.
CASE
ELSE 'D'
END AS GRADE
FROM GRADES;
Q3) Write a SQL query to apply a discount based on the product category
CASE
FROM PRODUCTS;
SECTION5 – Subqueries: 3Q’s
Q1) Write a query to find all customers who have spent more than the average purchase amount.
FROM PURCHASES
Q2)Find total sales by customer, add a column showing total sales for each customer
Ans --
FROM SALES
GROUP BY CustomerID;
Q3) Find top sales per customer, highest sales for each customer (refer to Q2 – SALES table of this section for your reference)
FROM SALES
GROUP BY CustomerID;
----------------------------------------------------------------------------ANSWERS---------------------------------------------------------------------------------------