- 79
- 57 016
The Data -Tech Club
India
เข้าร่วมเมื่อ 17 ม.ค. 2023
Here We Talk and Teach about SQL, Excel, Python, PowerBI, Tableau, QlikView and AI Tools.
My name is Arshad, from the Data - Tech Club. I am a Data and Tech Enthusiast.
I worked as a data analyst at RBS and other MNCs for 6 years.
My Expertise in Technology and Data Analysis. I always try to learn new technologies and love to share my knowledge with others.
If you are looking for Professional Training in above technologies -- you've come to the right place.
The purpose of this channel to share knowledge with everyone, new tricks about data analysis, new technologies in AI, new tools and techniques which makes your job easier.
Please Subscribe and be informed with tech updates.
Happy Learning!!!!
Cheers.
My name is Arshad, from the Data - Tech Club. I am a Data and Tech Enthusiast.
I worked as a data analyst at RBS and other MNCs for 6 years.
My Expertise in Technology and Data Analysis. I always try to learn new technologies and love to share my knowledge with others.
If you are looking for Professional Training in above technologies -- you've come to the right place.
The purpose of this channel to share knowledge with everyone, new tricks about data analysis, new technologies in AI, new tools and techniques which makes your job easier.
Please Subscribe and be informed with tech updates.
Happy Learning!!!!
Cheers.
How to Find 2nd & 3rd Highest Salary per Department in SQL | KPMG Interview Question | DENSE_RANK
In this video, I will walk you through an SQL Server interview question asked at KPMG, where we calculate the second and third highest salary per department using the DENSE_RANK() window function. This is a common SQL interview topic, and understanding how to handle ranking functions like DENSE_RANK() will help you tackle many complex SQL problems in your interviews and real-world projects.
I will explain the query step-by-step, showing you how to use DENSE_RANK() with PARTITION BY and MAX() to extract the second and third highest salaries for each department. If you're preparing for an SQL Server interview or just want to improve your SQL skills, this tutorial is perfect for you!
🔍 Key Topics Covered:
SQL Server DENSE_RANK() Function
Window Functions Explained
SQL Query for Finding 2nd & 3rd Highest Salary
KPMG SQL Interview Question
🔔 Don’t forget to like, comment, and subscribe for more SQL tutorials!
.
.
.
.
#SQLInterview #SQLServer #SQLTutorial #KPMGInterview #SQLWindowFunctions #SQLRankingFunctions #DENSE_RANK #SQLQuery #SQLServerInterview #SQLQueries #InterviewPreparation #TechInterview #SQLTips #LearnSQL #SQLTraining #techskills .
.
.
.
.
----------------------------Table Script--------------------------------------------------
CREATE TABLE employee_data (department VARCHAR(100), employee_id BIGINT, hire_date DATETIME, rank FLOAT, salary BIGINT);
INSERT INTO employee_data (department, employee_id, hire_date, rank, salary) VALUES ('HR', 101, '2022-01-15', 5.0, 60000), ('HR', 102, '2021-03-10', 4.5, 75000), ('HR', 103, '2020-05-20', 4.2, 75000), ('HR', 104, '2023-06-01', 4.0, 50000), ('Finance', 201, '2020-07-15', 3.8, 85000), ('Finance', 202, '2021-09-25', 4.1, 95000), ('Finance', 203, '2023-03-30', 4.3, 95000), ('Finance', 204, '2022-11-12', 4.0, 70000), ('IT', 301, '2021-12-11', 5.0, 120000), ('IT', 302, '2023-01-15', 4.5, 110000), ('IT', 303, '2020-08-19', 4.8, 105000), ('IT', 304, '2021-06-30', 4.1, 100000), ('Sales', 401, '2019-11-20', 4.7, 65000), ('Sales', 402, '2022-02-10', 4.5, 55000), ('Sales', 403, '2020-01-25', 4.3, 75000), ('Sales', 404, '2023-07-18', 4.0, 72000);
I will explain the query step-by-step, showing you how to use DENSE_RANK() with PARTITION BY and MAX() to extract the second and third highest salaries for each department. If you're preparing for an SQL Server interview or just want to improve your SQL skills, this tutorial is perfect for you!
🔍 Key Topics Covered:
SQL Server DENSE_RANK() Function
Window Functions Explained
SQL Query for Finding 2nd & 3rd Highest Salary
KPMG SQL Interview Question
🔔 Don’t forget to like, comment, and subscribe for more SQL tutorials!
.
.
.
.
#SQLInterview #SQLServer #SQLTutorial #KPMGInterview #SQLWindowFunctions #SQLRankingFunctions #DENSE_RANK #SQLQuery #SQLServerInterview #SQLQueries #InterviewPreparation #TechInterview #SQLTips #LearnSQL #SQLTraining #techskills .
.
.
.
.
----------------------------Table Script--------------------------------------------------
CREATE TABLE employee_data (department VARCHAR(100), employee_id BIGINT, hire_date DATETIME, rank FLOAT, salary BIGINT);
INSERT INTO employee_data (department, employee_id, hire_date, rank, salary) VALUES ('HR', 101, '2022-01-15', 5.0, 60000), ('HR', 102, '2021-03-10', 4.5, 75000), ('HR', 103, '2020-05-20', 4.2, 75000), ('HR', 104, '2023-06-01', 4.0, 50000), ('Finance', 201, '2020-07-15', 3.8, 85000), ('Finance', 202, '2021-09-25', 4.1, 95000), ('Finance', 203, '2023-03-30', 4.3, 95000), ('Finance', 204, '2022-11-12', 4.0, 70000), ('IT', 301, '2021-12-11', 5.0, 120000), ('IT', 302, '2023-01-15', 4.5, 110000), ('IT', 303, '2020-08-19', 4.8, 105000), ('IT', 304, '2021-06-30', 4.1, 100000), ('Sales', 401, '2019-11-20', 4.7, 65000), ('Sales', 402, '2022-02-10', 4.5, 55000), ('Sales', 403, '2020-01-25', 4.3, 75000), ('Sales', 404, '2023-07-18', 4.0, 72000);
มุมมอง: 315
วีดีโอ
Advanced SQL Interview Question Explained: CTE, Joins, and Grouping for Microsoft SQL Interviews
มุมมอง 1289 ชั่วโมงที่ผ่านมา
Are you preparing for a Microsoft SQL Server interview? 🚀 This video breaks down a real-world SQL interview question with step-by-step solutions! Learn how to manage employee_details and bonus tables, handle data relationships, and craft efficient SQL queries for scenarios involving salary, bonus calculations, and employee hierarchy. Whether you're a beginner or a seasoned SQL professional, thi...
EY SQL Interview Question Solved Step-by-Step
มุมมอง 12612 ชั่วโมงที่ผ่านมา
In this video, we solve an advanced SQL question that involves using Common Table Expressions (CTEs), ROW_NUMBER(), and DENSE_RANK() to track consecutive attendance records. This type of question is common in EY (Ernst & Young) SQL interviews and helps you understand: ✅ How to use ROW_NUMBER() and DENSE_RANK() effectively. ✅ Grouping attendance periods with calculated differences (RN - DN). ✅ F...
Amazon SQL Interview: Handle NULLs Like a Pro | Advance SQL Interview Question
มุมมอง 13014 ชั่วโมงที่ผ่านมา
n this video, we walk through an Amazon SQL interview question where we create and manage a jobs table that contains NULL values in certain rows. We’ll explore how to handle NULL values in SQL and perform calculations like summing the expenditure and person days for various jobs. 🔑 Key Topics Covered: How to create a table with VARCHAR and INT data types. Dealing with NULL values in SQL queries...
Walmart SQL Interview Question: Calculate Highest Budget Per Employee (Step-by-Step Guide)
มุมมอง 13014 ชั่วโมงที่ผ่านมา
In this session, we solve a commonly asked SQL problem: "How to select projects with the highest budget-per-employee ratio from related tables like Projects and Employees?" We walk through: ✅ Using WITH Common Table Expressions (CTEs) ✅ Joining tables effectively (Projects and Employees) ✅ Calculating employee counts per project ✅ Optimizing SQL queries for better performance ✅ Finding the high...
Capgemini SQL Interview: Optimized Queries for Summing Traveled Distance by User
มุมมอง 38419 ชั่วโมงที่ผ่านมา
In this video, I walk through a Capgemini SQL interview question where we need to calculate the sum of traveled distance for each user. I'll demonstrate two approaches: one using a GROUP BY clause and another with a SUM() OVER window function. I’ll also share tips on optimizing the queries for better performance. Don't forget to like, subscribe, and hit the bell icon for more SQL tutorials! . ....
Amazon SQL Interview: Swap Gender Values Using CASE Statement
มุมมอง 16321 ชั่วโมงที่ผ่านมา
Learn how to tackle an Amazon SQL interview question where you need to swap gender values in a dataset using the CASE statement. This tutorial explains the query step-by-step to transform 'M' to 'F' and 'F' to 'M'. Perfect for anyone preparing for SQL-based interviews or improving their SQL skills. Watch now to master this essential concept and ace your next interview! . . . . #AmazonSQLIntervi...
SQL Running Total Without Window Functions - KPMG Interview Question Explained
มุมมอง 171วันที่ผ่านมา
In this video, we demonstrate how to generate a running total in SQL without using window functions, which is a common interview challenge at top companies like KPMG. Using recursive Common Table Expressions (CTE), we calculate running totals step-by-step. This technique can be extremely useful for managing cumulative sums in databases when window functions are not available or permitted. Learn...
Top SQL Interview Question at PwC | Recursive CTE Explained | Factorial Example | SQL for Beginners
มุมมอง 96วันที่ผ่านมา
Description: In this video, learn how to calculate a factorial using a recursive Common Table Expression (CTE) in SQL. We’ll break down the query step by step to help you understand how recursion works in SQL, from initializing the base case to processing each iteration. 💡 Topics Covered: What is a CTE How to use recursive CTEs Calculating factorials in SQL SQL recursion explained for beginners...
Master SQL Query: Fetch 3rd Highest Salary Without Analytical Functions!
มุมมอง 456วันที่ผ่านมา
Learn how to write an SQL query to fetch the third-highest salary in SQL Server without using analytical functions like ROW_NUMBER, RANK, or DENSE_RANK. This step-by-step tutorial explores two different approaches: one using a nested subquery and the other using Common Table Expressions (CTE). Perfect for SQL interview preparation and understanding advanced query techniques. Watch now to master...
Amazon Interview Question | SQL Query to Find Customers with 50%+ Orders in the Last Month
มุมมอง 340หลายเดือนก่อน
In this video, learn how to write an SQL query to find customers who placed 50% or more of their orders in the last month using the Northwind database. This step-by-step tutorial explains the logic behind the query and demonstrates its implementation. Perfect for SQL learners, data analysts, and developers looking to enhance their query-writing skills. 💡 Topics Covered: SQL query structure Usin...
ENY interview Question | Divide Employees Into Teams Using Salary | CTE and DENSE_RANK Explained
มุมมอง 340หลายเดือนก่อน
n this video, learn how to solve an advanced SQL interview question: dividing employees into teams based on salary using CTEs, GROUP BY, HAVING, and the DENSE_RANK() function. We’ll guide you through the process step-by-step to create a query that satisfies the given conditions: Each team must consist of at least two employees. All employees on a team must have the same salary. Employees with u...
Tiger Analytics Interview Question | Cumulative Sum Without Window Functions | Self-Join Explained
มุมมอง 541หลายเดือนก่อน
In this video, learn how to calculate a cumulative sum in SQL using a self-join , an essential concept for SQL interview preparation. We’ll break down the logic step-by-step, explaining how the join condition. ensures that for each row, only the current and preceding rows contribute to the cumulative total. This method avoids using advanced window functions and showcases SQL's versatility in so...
Apple Interview Question | 🚀 Master Grouping, CTEs, and Joins with Real-World Examples 💼
มุมมอง 208หลายเดือนก่อน
Master SQL with this advanced interview question! 🚀 Learn how to solve a real-world SQL problem involving Apple product users and total users with devices, grouped by language. This tutorial covers essential SQL concepts like Common Table Expressions (CTEs), JOINs, GROUP BY, and efficient filtering techniques to handle complex datasets. We’ll use two tables, playbook_users and playbook_events, ...
Microsoft SQL Interview Question (Medium Level) | Find the Company with Most Desktop-Only Users
มุมมอง 471หลายเดือนก่อน
In this video, we solve a medium-level SQL interview question using Common Table Expressions (CTEs) to identify the company (customer ID) with the highest number of users who exclusively use desktops. This problem is an excellent example of how to handle filtering, grouping, and ranking in SQL for real-world analytics scenarios. What You'll Learn: ✅ How to filter data with NOT IN to exclude spe...
American Express Interview | SQL Interview Question: Calculate Salary Difference Between Departments
มุมมอง 196หลายเดือนก่อน
American Express Interview | SQL Interview Question: Calculate Salary Difference Between Departments
PayPal SQL Interview Question Explained | Master SQL for Data Interviews | Advanced SQL #learnsql
มุมมอง 555หลายเดือนก่อน
PayPal SQL Interview Question Explained | Master SQL for Data Interviews | Advanced SQL #learnsql
Amazon interview Question | SQL Interview Question Breakdown: Step-by-Step Solution | Advanced SQL
มุมมอง 419หลายเดือนก่อน
Amazon interview Question | SQL Interview Question Breakdown: Step-by-Step Solution | Advanced SQL
Amazon SQL Interview Questions: How to Solve Like a Pro | Advanced SQL Interview Question
มุมมอง 288หลายเดือนก่อน
Amazon SQL Interview Questions: How to Solve Like a Pro | Advanced SQL Interview Question
Amazon SQL Interview Question: Solving Common SQL Challenges with Real-World Examples
มุมมอง 232หลายเดือนก่อน
Amazon SQL Interview Question: Solving Common SQL Challenges with Real-World Examples
AirBnb Interview | Common SQL Interview Question Answered | Boost Your Job Prep
มุมมอง 1292 หลายเดือนก่อน
AirBnb Interview | Common SQL Interview Question Answered | Boost Your Job Prep
Ace SQL Interviews | Detailed Solution to a Common Question | SQL Interview Question no 26
มุมมอง 1072 หลายเดือนก่อน
Ace SQL Interviews | Detailed Solution to a Common Question | SQL Interview Question no 26
Must-Know SQL Interview Question | Perfect Answer Explained | SQL Interview Question no 25 #data
มุมมอง 1222 หลายเดือนก่อน
Must-Know SQL Interview Question | Perfect Answer Explained | SQL Interview Question no 25 #data
SQL Interview Preparation: Solving Top Questions with Ease | 24 Daily Advanced SQL Practice
มุมมอง 1332 หลายเดือนก่อน
SQL Interview Preparation: Solving Top Questions with Ease | 24 Daily Advanced SQL Practice
Cisco SQL Interview Question | SQL Interview Question no 23 | Daily SQL Practice | Advanced SQL
มุมมอง 2922 หลายเดือนก่อน
Cisco SQL Interview Question | SQL Interview Question no 23 | Daily SQL Practice | Advanced SQL
Swiggy SQL Interview Question | SQL Interview Question no 22 | Daily SQL Practice | Advanced SQL
มุมมอง 5312 หลายเดือนก่อน
Swiggy SQL Interview Question | SQL Interview Question no 22 | Daily SQL Practice | Advanced SQL
Zomato Interview Question | SQL Interview Question no 21 | Daily SQL Practice | Advanced SQL
มุมมอง 4312 หลายเดือนก่อน
Zomato Interview Question | SQL Interview Question no 21 | Daily SQL Practice | Advanced SQL
Adobe Interview Question | SQL Interview Question no 20 | Daily SQL Practice | Advanced SQL
มุมมอง 2142 หลายเดือนก่อน
Adobe Interview Question | SQL Interview Question no 20 | Daily SQL Practice | Advanced SQL
Deloitte Interview Question | | SQL Interview Question no 19 | Daily SQL Practice | Advanced SQL
มุมมอง 7802 หลายเดือนก่อน
Deloitte Interview Question | | SQL Interview Question no 19 | Daily SQL Practice | Advanced SQL
LinkedIn Interview Question | SQL Interview Question no 18 | Daily SQL Practice | Advanced SQL
มุมมอง 4802 หลายเดือนก่อน
LinkedIn Interview Question | SQL Interview Question no 18 | Daily SQL Practice | Advanced SQL
Here is my approach : select concat(year(month),"-0", month(month)) as `month`, max(case when category = 'Clothing' then sales end) as Clothing, min(case when category = 'Electronics' then sales end) as Electronics, max(case when category = 'Grocery' then sales end) as Grocery from paypal_sales_data group by 1 order by 1 desc;
Nice video! I am new to this field, and I learned a lot from it. A small tip-please share the data link so we can also practice. Also, consider making a video on a portfolio project. Thanks for sharing your knowledge!
Highly appreciate!
That's a great approach of problem solving Sir, Make more videos of SQL Questions , Sir . 😀
keep going sir appreciate your work
Appreciate the support! Keep learning. 😊
with cte as( select *, DATEADD(DAY, -1*ROW_NUMBER() over (partition by employee, status order by dates), DATES) FLAG from ATTENDANCE_TUE ), cte2 as( select *, FIRST_VALUE(DATES) over (partition by employee, FLAG order by DATES) start_date, FIRST_VALUE(DATES) over (partition by employee, FLAG order by DATES DESC) end_date from cte ) select distinct employee,start_date , end_date, status from cte2
My Approach : WITH cte AS ( SELECT *, DAY(dates) - ROW_NUMBER() OVER(PARTITION BY employee, status ORDER BY Dates) AS diff FROM attendance ORDER BY dates ) SELECT employee, MIN(dates) AS From_Date, MAX(dates) AS To_Date, status FROM cte GROUP BY employee, status, diff;
If we have N number of rows we can't write N number of lag functions right?
Big Thanks to ask this question. yes, we can't write if we have 10000 rows for that. That was the temporary solution and demonstration of lag function to deal with nulls. If we have such situations and we do not want to write LAG so i have a solution for this. Please check the code below and ask me if you have any questions. with cte as ( select workname,person_days, expenditure, row_number() over (order by (select null)) rn1 from jobs ), Ncte as ( select workname,person_days, expenditure, row_number() over (order by (select null)) - 1 rn2 from cte ) SELECT t1.workname, (SELECT top 1 t2.workname FROM Ncte t2 WHERE t2.rn2 < t1.rn1 AND t2.workname IS NOT NULL ORDER BY t2.rn2 DESC ) New_workname,t1.person_days, t1.expenditure FROM cte t1;
Nice explanation 👌 👍 👏
Thanks! Glad you found it helpful.
Super 👍
My approach : with cte as (select customer_id,order_amount, dense_rank() over(partition by customer_id order by max(order_date) desc) as rnk from az_orderss group by 1,2) select customer_id,max(case when rnk=1 then order_amount end) as latest_order_amount, min(case when rnk=2 then order_amount end) as second_latest_order_amount from cte group by customer_id;
select user_id,company_id,language from capgemini_user where language in ('English','German') and user_id in ( select user_id from capgemini_user where language in ('English','German') group by company_id,user_id having count(user_id)>1);
Why is the volume always less in your videos?
Volume in the video is completely fine.
I Will check and try to improve
Superb explanation 👌 👏 👍
Thank you, keep learning ☺️
with cte as (select user_id,count(distinct follower_id) as num from famous group by user_id), cte2 as (select *,sum(num) over() as sm from cte) select user_id,(num/sm)*100 as famous from cte2
WITH cte AS ( SELECT company_id , user_id, COUNT(CASE WHEN language IN ('german' , 'english') THEN 1 ELSE NULL END) AS count_ FROM company_user GROUP BY company_id , user_id ) SELECT a.user_id , b.company_id , b.language FROM cte as a , company_user as b WHERE a.user_id = b.user_id and a.count_ = 2
Happy to see you back
more video on joins
WITH cte AS ( SELECT u.user_id, u.user_name, f.friend_id, f1.user_name AS friend_name FROM users u LEFT JOIN friends f ON u.user_id = f.user_id LEFT JOIN users f1 ON f.friend_id = f1.user_id WHERE u.user_name IN ('Karl','Hans') ) SELECT c1.user_name AS friend_1, c2.user_name AS friend_2, c1.friend_name AS Mutual_friend FROM cte c1 JOIN cte c2 ON c1.user_id != c2.user_id AND c1.friend_id = c2.friend_id AND c1.user_name < c2.user_name;
WITH cte AS ( SELECT *, DAY(purchase_date) - DENSE_RANK() OVER(PARTITION BY empid ORDER BY purchase_date) AS diff FROM purchases ) SELECT empid FROM cte GROUP BY empid, diff HAVING COUNT(*) >= 3;
WITH cte AS ( SELECT *, MINUTE(updated_time) - ROW_NUMBER() OVER(PARTITION BY status ORDER BY MINUTE(updated_time)) AS diff FROM service_log WHERE status = 'down' ) SELECT service_name, status, MIN(updated_time) AS start_time, MAX(updated_time) AS end_time FROM cte GROUP BY service_name, status, diff HAVING COUNT(*) >= 5;
WITH cte AS ( SELECT customer_Id, order_date, order_amount, ROW_NUMBER() OVER(PARTITION BY customer_id ORDER BY order_date DESC) AS rn FROM orders ) SELECT customer_ID, SUM(CASE WHEN rn = 1 THEN order_amount ELSE 0 END) AS latest_order_amount, SUM(CASE WHEN rn = 2 THEN order_amount ELSE 0 END) AS second_latest_order_amount FROM cte WHERE rn <= 2 GROUP BY customer_ID;
WITH cte AS ( SELECT e.salary, ROW_NUMBER() OVER(PARTITION BY d.department ORDER BY salary DESC) AS rn FROM employee e JOIN dept d ON e.department_id = d.id WHERE d.department IN ('marketing', 'engineering') ) SELECT ABS(c1.salary - c2.salary) AS Absolute_diff FROM cte c1 JOIN cte c2 ON c1.rn = 1 AND c2.rn = 1 AND c1.salary > c2.salary;
SELECT u.language, SUM(CASE WHEN LOWER(device) LIKE '%macbook%' OR LOWER(device) LIKE '%iphone%' OR LOWER(device) LIKE '%ipad%' THEN 1 ELSE 0 END) AS iphone_users_cnt, COUNT(*) AS total_users FROM playbook_users u JOIN playbook_events e ON u.user_id = e.user_id GROUP BY language ORDER BY total_users DESC;
My Approach : WITH cte AS ( SELECT *, id - ROW_NUMBER() OVER(ORDER BY visit_date) AS rn FROM stadium WHERE people >= 100 ) SELECT * FROM cte WHERE rn = (SELECT rn FROM cte GROUP BY rn HAVING COUNT(visit_date) >= 3 );
My Approach : WITH cte AS ( SELECT *, id - ROW_NUMBER() OVER(PARTITION BY num ORDER BY id) AS diff FROM series1 ) SELECT num FROM cte GROUP BY num, diff HAVING COUNT(*) >= 3;
with cte as ( select Company_Id, User_Id, group_concat(Language) as grp from Company_user group by Company_Id, User_Id ) select * from cte where grp = 'German,English' or grp = 'English,German';
WITH CTE AS( SELECT *, count(USER_ID) OVER(PARTITION BY USER_ID) ATLEAST_2 FROM COMPANY_USER WHERE LANGUAGE IN( 'ENGLISH' ,'GERMAN')) SELECT * FROM CTE WHERE G=2;
Thanks sir
with temp as ( select user_id from Company_user where Language in ("English","German") group by user_id having count(Language) = 2 ) select company_id from Company_user where user_id in (select user_id from temp) group by company_id having count(distinct(user_id)) >= 2
select user_id,count(language) from company_user where language in('English','German') group by user_id having count(language)=2
This is exactly what I thought too. Since the data is less, you were able to put in as not in Spanish. But in a large table, its not easy to filter the data we dont need. The best one is to put in the filter on the data we need.
sound quality vary poor, but vedio contion good
Appreciate the kind words about the content! I'll work on the audio.
voice not clear
thank
thanks
please provide table
please provide dataet also
sir increase sound quality please
Plese provide the ddl and dml commands for practice for small dataset or the dataset you have used in your video
amazing series
Alternate approach with OVER clause: - with cte as ( SELECT *, COUNT(name) OVER (partition by salary) as cnt FROM company ) select dense_rank() OVER (order by salary) as team_id, emp_id,name,salary from cte where cnt = 2
with cte as( select * FROM new_sale ),cte1 as( select cte.*,new_sale.salary as salary1 FROM cte JOIN new_sale ON cte.Date>=new_sale.Date ORDER BY Date ) select Date,SUM(salary1) as sum2 FROM cte1 GROUP BY Date ORDER BY Date;
with cte as( select playbook_users.user_id,language,device FROM playbook_users JOIN playbook_events ON playbook_users. user_id=playbook_events.user_id ) select language,COUNT(DISTINCT user_id) as total_count, COUNT(DISTINCT CASE when device IN ('MacBook-Pro','iPhone 5s','iPad-air') THEN user_id ELSE NULL END) as apple_users FROM cte GROUP BY language;
Bro if you find any kind of error in my query on any solutions I post in it, plese comment also for the same
Sure
with cte as( select customer_id,COUNT(*) as c1, COUNT(CASE when client_id="desktop" THEN 1 ELSE NULL END) as x1 FROM fact_events GROUP BY customer_id ) select customer_id FROM (select cte.*,DENSE_RANK()OVER(ORDER BY c1 DESC) as r1 FROM cte where c1=x1) as es where r1=1;
WITH ConsecutiveDownPeriods AS ( SELECT Date, ServerStatus, ROW_NUMBER() OVER (PARTITION BY ServerStatus ORDER BY Date) - ROW_NUMBER() OVER (ORDER BY Date) AS GroupNum FROM YourTableName ) SELECT MAX(DATEDIFF(day, MIN(Date), MAX(Date)) + 1) AS MaxConsecutiveDownDays FROM ConsecutiveDownPeriods WHERE ServerStatus = 'down' GROUP BY GroupNum;
nice video
Thank you 👍
with cte as( select salary,department FROM db_employee JOIN db_dept ON db_employee.department_id=db_dept.id ),cte1 as( select department,MAX(salary) as dept_sal FROM cte GROUP BY department HAVING department IN ('marketing','engineering') ),cte2 as( select cte1.*,LEAD(dept_sal)OVER() as second_dept_sal FROM cte1 ) select (dept_sal-second_dept_sal) as diff FROM cte2 where (dept_sal-second_dept_sal) is not null;
Can we use max(salary) over (partition by department_id)
Yes, it will work.
select MONTHNAME(month) as month_name, SUM(CASE when category="Electronics" THEN sales ELSE NULL END) as Electronics, SUM(CASE when category="Clothing" THEN sales ELSE NULL END) as Clothing, SUM(CASE when category="Grocery" THEN sales ELSE NULL END) as Grocery FROM sales_data GROUP BY MONTHNAME(month);