Data Science Corner
Data Science Corner
  • Видео 24
  • Просмотров 9 161
SQL Interview Question 2024 | Recursive CTE to retrieve the hierarchical structure of employees
In this video, I have discussed how to solve the SQL Interview Questions: Write an SQL query using a recursive CTE to retrieve the hierarchical structure of employees.
-- Creating the Employees Table
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY, -- Unique identifier for each employee
ManagerID INT NULL, -- This refers to the EmployeeID of the manager (NULL if top-level employee)
EmployeeName VARCHAR(100) NOT NULL -- Name of the employee
);
-- Inserting Sample Data
INSERT INTO Employees (EmployeeID, ManagerID, EmployeeName)
VALUES
(1, NULL, 'Alice'),
(2, 1, 'Bob'),
(3, 1, 'Charlie'),
(4, 2, 'David'),
(5, 2, 'Eve'),
(6, 3, 'Frank'),
(7, 4, 'Grace');
SQL Interview QnAs: ruclips.net/p/PLg_hSL...
Просмотров: 334

Видео

SQL Interview Question 2024 | Find books published in the last year and corresponding authors
Просмотров 2322 месяца назад
In this video, I have discussed how to solve the SQL Interview Questions: 1. List all authors and number of books written 2. Find books published in the last year and corresponding authors Create Authors table CREATE TABLE Authors ( AuthorID INT PRIMARY KEY, AuthorName VARCHAR(100) ); Create Books table CREATE TABLE Books ( BookID INT PRIMARY KEY, AuthorID INT, BookTitle VARCHAR(200), Publicati...
Capgemini SQL Interview Question 2024 | Retrieve the total revenue generated from each product
Просмотров 3082 месяца назад
In this video, I have discussed how to solve the Capgemini SQL Interview Questions: 1. Retrieve the total revenue generated from each product. 2. Find products that have not been ordered at all. Create Products table CREATE TABLE Products ( ProductID INT PRIMARY KEY, ProductName VARCHAR(100), ProductPrice DECIMAL(10, 2) ); Create Orders table CREATE TABLE Orders ( OrderID INT PRIMARY KEY, Produ...
PWC SQL Interview Question 2024 | Time Series Data I Find the Average Temperature for Each Day
Просмотров 1722 месяца назад
In this video, I have discussed how to solve the PWC SQL Interview Questions: Find the Average Temperature for Each Day? 1. Create table CREATE TABLE temperature_readings ( reading_id SERIAL PRIMARY KEY, sensor_id INT, reading_time TIMESTAMP, temperature NUMERIC ); 2. Insert records INSERT INTO temperature_readings (sensor_id, reading_time, temperature) VALUES (1, '2024-07-01 08:00:00', 25.4), ...
KPMG SQL Interview Question 2024 | Find out the Studentwise Total Marks for Top 2 Subjects
Просмотров 8572 месяца назад
In this video, I have discussed how to solve the KPMG SQL Interview Questions: Find out the Studentwise Total Marks for Top 2 Subjects? 1. Create the student table CREATE TABLE students ( student_name VARCHAR(50), subject VARCHAR(50), marks INT ); 2. Insert records into the student table INSERT INTO students (student_name, subject, marks) VALUES ('Alice', 'Math', 65), ('Alice', 'Science', 80), ...
Deloitte SQL Interview Question 2024 | Classify employees into different performance levels
Просмотров 2712 месяца назад
In this video, I have discussed how to solve the SQL Interview Questions: Classify employees into different performance levels based on both performance rating and salary: 'Top Performer' for 'Excellent' rating and salary greater than 7000, 'Good Performer' for 'Good' rating and salary greater than 5000, and 'Others' for all other combination Query to create table: CREATE TABLE employees ( empl...
UST Global SQL Interview Question 2024 | Identifying Gaps in a Sequence
Просмотров 2412 месяца назад
In this video, I have discussed how to solve the SQL Interview Questions: Given a table orders with columns order_id (sequential integers), order_date, write a query to identify the missing order IDs. Query to create table: CREATE TABLE orders ( order_id INT PRIMARY KEY, order_date DATE ); Insert Data INSERT INTO orders (order_id, order_date) VALUES (1, '2024-07-01'), (2, '2024-07-02'), (3, '20...
Deloitte SQL Interview Question 2024 | Find the top 3 highest-paid employees in each department I
Просмотров 6863 месяца назад
In this video, I have discussed how to solve the SQL Interview Questions: Part 1: Find the top 3 highest-paid employees in each department. Part 2: Find the average salary of employees hired in the last 5 years. Part 3: Find the employees whose salry is less than the average salary of employees hired in the last 5 years. Query to create table: CREATE TABLE Departments ( DepartmentID INT PRIMARY...
Capgemini SQL Interview Question 2024 | Transform Rows Into Columns
Просмотров 1,8 тыс.3 месяца назад
In this video, I have discussed how to solve the SQL Interview Question: Transform Rows Into Columns: Query to create table: CREATE TABLE sales_data ( month varchar(10), category varchar(20), amount numeric ); Insert data INSERT INTO sales_data (month, category, amount) VALUES ('January', 'Electronics', 1500), ('January', 'Clothing', 1200), ('February', 'Electronics', 1800), ('February', 'Cloth...
Cognizant SQL Interview Question | Extract the Domain from the Email Column in Employee Table
Просмотров 7913 месяца назад
In this video, I have discussed how to solve the SQL Interview Question: Extract the domain name from email column in employee table: SQL Interview QnAs: ruclips.net/p/PLg_hSLs-7hbtyGn5vf5ErN6oo0CcILhfz PySpark Basic to Advance: ruclips.net/p/PLg_hSLs-7hbvIqzZgvViJcxkW09yOwg3L Python Basic to Advance Hands-on: ruclips.net/p/PLg_hSLs-7hbt_ypDKhEOS0NMR7ttFtrYF Resume Building and Interview Preps:...
PySpark Interview Question | Count the number of words in each line of a text file
Просмотров 853 месяца назад
In this video, I have discussed how to solve the PySprak Interview Question Asked in Persistent: Write a PySpark program to count the number of words in each line of a text file? PySpark Basic to Advance: ruclips.net/p/PLg_hSLs-7hbvIqzZgvViJcxkW09yOwg3L SQL Interview QnAs: ruclips.net/p/PLg_hSLs-7hbtyGn5vf5ErN6oo0CcILhfz Python Basic to Advance Hands-on: ruclips.net/p/PLg_hSLs-7hbt_ypDKhEOS0NMR...
SQL Interview Question | Use Different Methods to Find the Nth Highest Salary
Просмотров 2,2 тыс.3 месяца назад
SQL Interview Question | Use Different Methods to Find the Nth Highest Salary
4. StructType() & StructField() in PySpark
Просмотров 693 месяца назад
4. StructType() & StructField() in PySpark
3. Read csv file in to dataframe using PySpark I Hands on Tutorial I Basic to Advance
Просмотров 474 месяца назад
3. Read csv file in to dataframe using PySpark I Hands on Tutorial I Basic to Advance
2. Create Dataframe manually with hard coded value in PySpark I Hands on Tutorial I Basic to Advance
Просмотров 634 месяца назад
2. Create Dataframe manually with hard coded value in PySpark I Hands on Tutorial I Basic to Advance
1. PySpark I Hands on Tutorial I Basic to Advance
Просмотров 1044 месяца назад
1. PySpark I Hands on Tutorial I Basic to Advance
Infosys Launched13+ Free Certification Courses | Python, Java, Data Science | Students & Jobseekers
Просмотров 1952 года назад
Infosys Launched13 Free Certification Courses | Python, Java, Data Science | Students & Jobseekers
Module 2 | Variables, Casting and Data Types in Python | Hands on Course
Просмотров 862 года назад
Module 2 | Variables, Casting and Data Types in Python | Hands on Course
Module 1 | Introduction to Python for Data Science | Hands on Course
Просмотров 2542 года назад
Module 1 | Introduction to Python for Data Science | Hands on Course
Resume Building and Interview Preps I
Просмотров 862 года назад
Resume Building and Interview Preps I

Комментарии

  • @chinthalakishore7054
    @chinthalakishore7054 3 дня назад

    Great explanation sir❤

  • @madhusudhanreddyt2838
    @madhusudhanreddyt2838 6 дней назад

    IN SQL SERVER (SSMS) -- List all authors and number of books written select a.AuthorName, COUNT(b.BookID) as [Number of Books] from Authors as a LEFT OUTER JOIN Books as b on a.AuthorID = b.AuthorID group by a.AuthorName order by a.AuthorName; -- Find books published in the last year and corresponding authors select b.BookTitle, a.AuthorName, YEAR(b.PublicationYear) as PublicationYear, YEAR(GETDATE()) as CurrentYear, YEAR(GETDATE()) - 1 as LastYear from Authors as a inner join Books as b on a.AuthorID = b.AuthorID where YEAR(b.PublicationYear) = YEAR(GETDATE()) - 1; happy quering :)

  • @madhusudhanreddyt2838
    @madhusudhanreddyt2838 6 дней назад

    in sql server (ssms) -- Retrieve the total revenue generated from each product. ;with cte_totalrevenue as ( select p.ProductName, p.ProductPrice * o.Quantity as Revenue from products as p inner join orders as o on p.productid = o.productid ) select ProductName, SUM(Revenue) as Total_Revenue from cte_totalrevenue group by ProductName order by ProductName; select p.ProductName, SUM(p.ProductPrice * o.Quantity) as Total_Revenue from Products as p inner join Orders as o on p.ProductID = o.ProductID group by p.ProductName order by p.ProductName; -- Find products that have not been ordered at all. select p.ProductName, o.OrderID from products as p left outer join orders as o on p.productid = o.productid where o.OrderID is null; -- using subquery select p.ProductName from Products as p where p.ProductID not in (select o.ProductID from Orders as o)

  • @madhusudhanreddyt2838
    @madhusudhanreddyt2838 6 дней назад

    IN SQL SERVER (SSMS) select CAST(reading_time as date) as reading_date, CAST(AVG(temperature) as decimal(10, 2)) as avg_temperature from temperature_readings group by CAST(reading_time as date);

  • @madhusudhanreddyt2838
    @madhusudhanreddyt2838 6 дней назад

    in sql server using t-sql (ssms) -- find the highest salary select * from Employees_Data where Salary = ( select MAX(Salary) as Highest_Salary from Employees_Data) ;with cte_temp as ( select *, DENSE_RANK() OVER (ORDER BY Salary DESC) as Drnk from Employees_Data ) select EmployeeId, FirstName, LastName, Gender, Salary from cte_temp where cte_temp.Drnk = 1 select EmployeeId, FirstName, LastName, Gender, Salary from( select *, DENSE_RANK() OVER (ORDER BY Salary DESC) as Drnk from Employees_Data ) as temp where temp.Drnk = 1 -- find the 2nd highest salary select * from Employees_Data where Salary = ( select MAX(salary) from Employees_Data where Salary <( select MAX(Salary) from Employees_Data)) -- select * from Employees_Data where Salary = ( select top 1 salary from ( select distinct top 2 Salary from Employees_Data order by Salary desc) as temp order by Salary asc); -- ;with cte_temp as ( select *, DENSE_RANK() OVER (ORDER BY Salary DESC) as DRnk from Employees_Data ) select EmployeeId, FirstName, LastName, Gender, Salary from cte_temp where cte_temp.DRnk = 2 -- select * from Employees_Data as e1 where 2 = (select COUNT(DISTINCT Salary) from Employees_Data as e2 where e2.Salary >= e1.Salary) -- 2nd or 3rd or 10th declare @n int set @n = 2 select * from Employees_Data as e1 where @n = (select COUNT(DISTINCT Salary) from Employees_Data as e2 where e2.Salary >= e1.Salary) happy querying :)

  • @madhusudhanreddyt2838
    @madhusudhanreddyt2838 6 дней назад

    in sql server using t-sql (SSMS) -- using substring function select EmployeeID, FirstName+', '+LastName as EmployeeName, Salary, DateHired, EmailAddress, SUBSTRING(EmailAddress, CHARINDEX('@', EmailAddress) + 1, LEN(EmailAddress)) as [DomainName] from Employees_Domains -- using right function select EmployeeID, FirstName+', '+LastName as EmployeeName, Salary, DateHired, EmailAddress, RIGHT(EmailAddress, LEN(EmailAddress) - CHARINDEX('@', EmailAddress)) as DomainName from Employees_Domains -- get the user name using the substring function select EmployeeID, FirstName+', '+LastName as EmployeeName, Salary, DateHired, EmailAddress, SUBSTRING(EmailAddress, 1, CHARINDEX('@', EmailAddress) - 1) as [UserName] from Employees_Domains -- get the user name using the left function select EmployeeID, FirstName+', '+LastName as EmployeeName, Salary, DateHired, EmailAddress, LEFT(EmailAddress, CHARINDEX('@', EmailAddress) - 1) as UserName from Employees_Domains

  • @madhusudhanreddyt2838
    @madhusudhanreddyt2838 6 дней назад

    in sql server, -- using the pivot operator select month, [Clothing], [Electronics] from ( select month, category, amount from sales_data ) as Source_Data PIVOT ( SUM(amount) FOR category IN ([Clothing], [Electronics]) ) as Pivot_Data; -- without using the pivot operator select month, SUM(case when category = 'Clothing' THEN amount else null end) as [Clothing], SUM(case when category = 'Electronics' THEN amount else null end) as [Electronis] from sales_data group by month;

  • @madhusudhanreddyt2838
    @madhusudhanreddyt2838 6 дней назад

    for people who want the queries in T-SQL (working in SSMS) -- Find the top 3 highest-paid employees in each department. ;with cte_temp as ( select CONCAT(emp.FirstName, ' ', emp.LastName) as [Employee Name], emp.Salary, dept.DepartmentName, ROW_NUMBER() OVER (PARTITION BY emp.DepartmentID ORDER BY emp.Salary DESC) as RNo from Employees as emp inner join Departments as dept on emp.DepartmentID = dept.DepartmentID ) select [Employee Name], Salary from cte_temp where cte_temp.RNo <=3; -- find top employee in each department ;with cte_temp as ( select CONCAT(emp.FirstName, ' ', emp.LastName) as [Employee Name], emp.Salary, dept.DepartmentName, ROW_NUMBER() OVER (PARTITION BY emp.DepartmentID ORDER BY emp.Salary DESC) as RNo from Employees as emp inner join Departments as dept on emp.DepartmentID = dept.DepartmentID ) select [Employee Name],DepartmentName, Salary from cte_temp where cte_temp.RNo = 1; -- Find the average salary of employees hired in the last 5 years. select EmployeeID, FirstName+' '+LastName as EmployeeName, Salary, DateHired, YEAR(DateHired) as Hired_Year, YEAR(GETDATE()) as Current_Year, YEAR(GETDATE()) - YEAR(DateHired) as Year_Diff from Employees where YEAR(GETDATE()) - YEAR(DateHired) <= 5 select CAST(AVG(Salary) as decimal(10, 2)) as Avg_Salary from Employees where YEAR(GETDATE()) - YEAR(DateHired) <= 5 -- Find the employees whose salry is less than the average salary of employees hired in the last 5 years. select EmployeeID, FirstName+', '+LastName as [EmployeeName], Salary, DateHired from Employees where Salary < ( select CAST(AVG(Salary) as decimal(10, 2)) as Avg_Salary from Employees where YEAR(GETDATE()) - YEAR(DateHired) <= 5 ) thank you for the script which made my job easy... :)

  • @p_k_s67
    @p_k_s67 8 дней назад

    WITH CTE AS ( SELECT *, ROW_NUMBER() OVER(PARTITION BY student_name ORDER BY marks DESC) AS rnk FROM students ) SELECT student_name, SUM(marks) AS marks FROM CTE WHERE rnk <= 2 GROUP BY student_name;

  • @saipraneeth1660
    @saipraneeth1660 9 дней назад

    Select month, [electronics], [clothing] from ( select month, category,amount from input_tbl) as source PIVOT(sum(amount) for category in [(electronics),(clothing)] as pivot_table

  • @JanardhanaVlog
    @JanardhanaVlog 12 дней назад

    Super sir.please write the query to get the height salary name and development wise.

  • @entertainmenthub5066
    @entertainmenthub5066 15 дней назад

    Please put he create ans insert command also

  • @Soul-f3v
    @Soul-f3v 17 дней назад

    select * from sales_data pivot (sum(amount) for category in ([Electronics],[Clothing]))as piv_tbl;

  • @TarabShaikh-q9n
    @TarabShaikh-q9n 19 дней назад

    select month, SUM(case when category = 'Clothing' then amount end) as "Clothing", SUM(case when category = 'Electronics' then amount end) as "Electronics" from sales group by month order by month;

  • @rahidulislam3378
    @rahidulislam3378 22 дня назад

    Most simple way to solve the question: SELECT student_name, SUM(marks) [Total Marks] FROM students GROUP BY student_name

  • @prajju8114
    @prajju8114 Месяц назад

    with cte_topmarks as ( Select *,row_number() over(partition by student_name order by marks desc) as rnk from students ) Select student_name,sum(marks) as total_marks from cte_topmarks where rnk in(1,2) group by student_name

  • @dasubabuch1596
    @dasubabuch1596 2 месяца назад

    with t as ( select generate_series(1,20) as e ) select e as order_id from t where e not in (select order_id from order_0108);

  • @dasubabuch1596
    @dasubabuch1596 2 месяца назад

    select month, sum(case when category = 'Clothing' then Amount end) as Clothing, sum(case when category = 'Electronics' then Amount end) as Electronics from sales_data group by month order by month;

  • @dasubabuch1596
    @dasubabuch1596 2 месяца назад

    with t as ( select student_name, marks,dense_Rank()over(partition by student_name order by marks desc) as rnk from student_0108 ), t1 as ( select * from t where rnk <=2 ) select student_name,sum(marks) as marks from t1 group by student_name;

  • @Harini-x7t
    @Harini-x7t 2 месяца назад

    select reading_time,round(avg(temperature),2) as average_temperature from temperature_readings group by reading_time

    • @datasciencecorner
      @datasciencecorner 2 месяца назад

      Great to see that you're practicing well Keep it up! Our best wishes to you :)

  • @Harini-x7t
    @Harini-x7t 2 месяца назад

    q1 ) select p1.ProductName,p1.productid,sum(p1.productprice * p2.quantity) as total from products p1 inner join orders p2 on p1.productid=p2.productid group by p1.ProductName,p1.productid q2) select * from Products where ProductID not in (select productid from orders)

  • @satishgs5355
    @satishgs5355 2 месяца назад

    SELECT month, SUM(CASE WHEN category='Clothing' then amount end) as Clothing, SUM(CASE WHEN category='Electronics' then amount end) as Electronics FROM sales_data GROUP BY month;

    • @datasciencecorner
      @datasciencecorner 2 месяца назад

      Great! Keep practicing well! Our best wishes to you :)

  • @satishgs5355
    @satishgs5355 2 месяца назад

    WITH cte_table AS( SELECT month, category, amount, CASE WHEN month = 'January' THEN 1 WHEN month = 'February' THEN 2 WHEN month = 'March' THEN 3 WHEN month = 'April' THEN 4 END AS month_order FROM sales_data ) SELECT month,Clothing,Electronics FROM ( SELECT * FROM cte_table) AS source_table PIVOT( MAX(AMOUNT) FOR CATEGORY IN(Clothing,Electronics) ) AS pivot_table ORDER BY month_order

  • @satishgs5355
    @satishgs5355 2 месяца назад

    WITH orders_cte as( select order_id, LAG(order_id) over(order by order_id ) as prev_order_id from dsc_orders ) select order_id,prev_order_id+1 AS missing_order_id from orders_cte WHERE prev_order_id IS NOT NULL AND prev_order_id + 1 <> order_id AND prev_order_id + 1 < order_id ORDER BY missing_order_id;

  • @Manifestion_kannada
    @Manifestion_kannada 2 месяца назад

    Solve more questions on join and analytical functions

    • @datasciencecorner
      @datasciencecorner 2 месяца назад

      @Manifestion_kannada sure. will do that. Thank you :)

  • @Manifestion_kannada
    @Manifestion_kannada 2 месяца назад

    Date ( reading_ time ) is it work in Oracle SQL developer

    • @datasciencecorner
      @datasciencecorner 2 месяца назад

      @Manifestion_kannada will check and let you know

  • @ritupornadowerah3157
    @ritupornadowerah3157 2 месяца назад

    Nice explanation 👍

  • @user-gq6cg3ls7f
    @user-gq6cg3ls7f 3 месяца назад

    select value as order_id from generate_series(1,20) except select order_id from orders or with cte as( select *, ROW_NUMBER() over (order by order_id) RN, LEAD(order_id) over (order by order_id) - order_id as diff from orders) select order_id+1 order_id from cte where diff>1

  • @Manifestion_kannada
    @Manifestion_kannada 3 месяца назад

    How to solve in SQL developer

    • @datasciencecorner
      @datasciencecorner 3 месяца назад

      Oracle SQL doesn't have a built-in generate_series function like PostgreSQL. Instead, we can create a sequence of numbers using a recursive common table expression (CTE). Here's how you can achieve the same result in Oracle SQL Developer: WITH sequence AS ( SELECT MIN(order_id) AS start_id, MAX(order_id) AS end_id FROM orders ), numbers AS ( SELECT start_id AS order_id FROM sequence UNION ALL SELECT order_id + 1 FROM numbers JOIN sequence ON numbers.order_id < sequence.end_id ) SELECT s.order_id FROM numbers s LEFT JOIN orders o ON s.order_id = o.order_id WHERE o.order_id IS NULL ORDER BY s.order_id;

  • @MusicalShorts-hn1px
    @MusicalShorts-hn1px 3 месяца назад

    Amazing!

  • @Hope-xb5jv
    @Hope-xb5jv 3 месяца назад

    use Dense_rank instead of row_number because your logic fail when two employees have same salary in same department ----Assuming you want different salary top 3 salary employees But if you want only top 3 employees regardless of their same salary or different salary then row number is correct

    • @datasciencecorner
      @datasciencecorner 3 месяца назад

      Yes, Dense_rank is more beneficial when you two or more employees with similar salary and you only want the 3 distinct top salary.

  • @MusicalShorts-hn1px
    @MusicalShorts-hn1px 3 месяца назад

    Would be great if you could provide table creation vommand in description

    • @datasciencecorner
      @datasciencecorner 3 месяца назад

      I have added the queries to create the table and insert the values. Happy Learning :)

  • @rohitconnect
    @rohitconnect 3 месяца назад

    instead of using pivot/ cross tab we can also do the below which is can run on any platform SELECT months, sum(case when category='Clothing' then Amount end) as Clothing, sum(case when category='Electronic' then Amount end) as Electronic from Months group by months;

  • @chandanpatra1053
    @chandanpatra1053 3 месяца назад

    why you are not providing create & insert statement after every video in the description box. I have given this a feedback.

    • @datasciencecorner
      @datasciencecorner 3 месяца назад

      I have added the queries to create the table and insert the values. Will make a note of it to add in every video. Happy Learning :)

  • @vijay_madane03
    @vijay_madane03 3 месяца назад

    Sir thoda sa font size increase kro please.

    • @datasciencecorner
      @datasciencecorner 3 месяца назад

      Ok. From next video will increase the font size 👍

  • @monasanthosh9208
    @monasanthosh9208 3 месяца назад

    Select *,concat(replace(Name," ","."),"@",domins) as email from domin;

  • @rohitconnect
    @rohitconnect 3 месяца назад

    RIGHT(email,(len(email)-locate('@',domain))) should this work as well? i dont have Sever to test

  • @asterisk7138
    @asterisk7138 3 месяца назад

    Please upload a video on display domain name from the given email id

    • @datasciencecorner
      @datasciencecorner 3 месяца назад

      Sure. Will upload it tomorrow! Thank you for the suggestion :)

    • @datasciencecorner
      @datasciencecorner 3 месяца назад

      Hi! We have created a video on your request to display domain name. You can check it here: ruclips.net/video/LtOzjmiJTho/видео.html

    • @asterisk7138
      @asterisk7138 3 месяца назад

      @@datasciencecorner thank you

    • @datasciencecorner
      @datasciencecorner 3 месяца назад

      No worries. Happy to help!

  • @ViratSharma69
    @ViratSharma69 3 месяца назад

    at 6:09 isnt it pointless to do it with a subquery, you have already ordered them and they are distinct as well, just directly add limit and offset to the subquery and we'll get the answer. Also to fetch nth highest salary, offset should be n-1*

  • @tahir4876
    @tahir4876 3 месяца назад

    Great work! Keep making more!

  • @tahir4876
    @tahir4876 3 месяца назад

    Great work! Keep making more!

  • @poroking944
    @poroking944 2 года назад

    Looking forward the next part. Thank you