Тёмный
MeanLifeStudies
MeanLifeStudies
MeanLifeStudies
Подписаться
Hi,

I'm Mahendra, a post-graduate in Engineering with a passion for teaching, dedicated to breaking down the underlying principles and share concepts of various domains like Maths, Science, Aptitude, Engineering, IT, Software, and Data Analytics to help people understand and apply their knowledge meaningfully to lead their lives, and also I will be supporting students in crafting successful academic and career paths.

I'm a freelance Data Analyst/ Data Engineer. Also working as a freelance tutor (1-on-1) personal training for Data Analytics Tech Stack Like SQL, Python, Power BI, Statistics, Big Data Technology, PySpark.
Want to learn any technology as mentioned above? You can hire me for personal training. All details mentioned in my Medium About section.

Kindly subscribe and share this content with your friends and peers to help spread the word and make a positive impact on others' lives.

Thank You :)

To Contact:
mail Id: meetmahendra301@gmail.com

Conditional Statements in SQL
14:12
Месяц назад
Комментарии
@gsrsakhilakhil528
@gsrsakhilakhil528 7 часов назад
Thank you so much sir for making videos on daily after watching all your videos im feeling that im improving everyday
@harishsingh_424
@harishsingh_424 8 часов назад
Awesome 👍 Request you to please make a detailed video on the stored procedure. I have searched the entire youtube but not getting helpful
@MeanLifeStudies
@MeanLifeStudies 8 часов назад
Thank you. I will do it soon.
@AnandKumar-dc2bf
@AnandKumar-dc2bf 10 часов назад
You are making awesome vidoes hope u get much more viewerships...
@MeanLifeStudies
@MeanLifeStudies 9 часов назад
I really wish and Thank you so much for you support.
@ipsitapani8641
@ipsitapani8641 День назад
You plz give us the structure of table details
@MeanLifeStudies
@MeanLifeStudies День назад
Kindly excuse. I will provide shortly.
@MeanLifeStudies
@MeanLifeStudies 10 часов назад
I added table create and internet statements. Please check once.
@omilind
@omilind День назад
You're doing amazing work! Please create more scenario and case study questions for data analyst interviews. These are incredibly helpful. Thank you!
@MeanLifeStudies
@MeanLifeStudies День назад
I will definitely do that and thank you for supporting this channel.
@saquibzeya8452
@saquibzeya8452 День назад
transaction_id column is missing in create table and insert table
@MeanLifeStudies
@MeanLifeStudies День назад
Kindly excuse me for missing it in the description box. I updated it just now.
@manojroyal7180
@manojroyal7180 День назад
is it correct bro with cte as( select c.*,count(voter_id) as voters_count, candidate_id from candidates c join election e on c.id=e.candidate_id group by e.candidate_id, c.id,c.name) select name from cte where voters_count=(select max(voters_count) from cte)
@MeanLifeStudies
@MeanLifeStudies День назад
Hi, Yes, it is correct. But it is possible only when voters voted for multiple candidates, then their value of vote is 1 for each. But our condition is not similar to the actual of our election. If a voter is votes for three candidates, the value of each is shared by three parts. so we should consider that also right?
@manojroyal7180
@manojroyal7180 День назад
@@MeanLifeStudies yes I missed it thanks for reply
@__vishal__8788
@__vishal__8788 2 дня назад
keep it up❤❤❤
@MeanLifeStudies
@MeanLifeStudies 2 дня назад
Thank you so much for supporting.
@__vishal__8788
@__vishal__8788 2 дня назад
Hii..
@MeanLifeStudies
@MeanLifeStudies 2 дня назад
Hi
@bankimdas9517
@bankimdas9517 3 дня назад
Thanks for making this video. Please bring more questions on data analysis topic.
@MeanLifeStudies
@MeanLifeStudies 3 дня назад
Definitely. Thanks for supporting.
@user-gq6cg3ls7f
@user-gq6cg3ls7f 3 дня назад
with cte as( select sum(salesAmount) first_week_sales, StoreID, StoreName, DATEPART(WK, Date) weekly_transaction from sales_info where DATEPART(WK, Date) = 1 group by StoreID, DATEPART(WK, Date), StoreName ), cte2 as( select sum(salesAmount) last_week_sales, StoreID, DATEPART(WK, Date) weekly_transaction from sales_info where DATEPART(WK, Date) = 3 group by StoreID, DATEPART(WK, Date) ) select cte.StoreID, cte.StoreName, first_week_sales, last_week_sales, concat(round((last_week_sales - first_week_sales)/first_week_sales*100,2), '%') as percentage_sales_increament from cte inner join cte2 on cte.StoreID = cte2.StoreID
@vemulaharikrishnareddy2738
@vemulaharikrishnareddy2738 3 дня назад
If possible pls create interview MFQ's series
@MeanLifeStudies
@MeanLifeStudies 3 дня назад
Sorry, what is MFQ?
@vemulaharikrishnareddy2738
@vemulaharikrishnareddy2738 3 дня назад
@@MeanLifeStudies Interview questions most frequently asked
@vemulaharikrishnareddy2738
@vemulaharikrishnareddy2738 3 дня назад
Thanks so much for sharing valuable content🤩🤩, Small request pls add script in all the videos.
@MeanLifeStudies
@MeanLifeStudies 3 дня назад
I thought I was adding for all, excuse me if missed out for any video. I will definitely add from on without fail.
@vemulaharikrishnareddy2738
@vemulaharikrishnareddy2738 3 дня назад
@@MeanLifeStudies Thank you !!!!
@krishnasai5806
@krishnasai5806 4 дня назад
Is there any openings for freshers
@MeanLifeStudies
@MeanLifeStudies 4 дня назад
As of my knowledge there are very less openings for freshers.
@kaushikbendalam7396
@kaushikbendalam7396 5 дней назад
Simple Solution with out using CTE SELECT name, sum(runs_scored) AS total_runs FROM Matches JOIN Players ON Matches.player_id = Players.id GROUP BY player_id HAVING ( COUNT(CASE WHEN runs_scored >= 50 THEN 1 END) >=2 AND COUNT(CASE WHEN runs_scored = 0 THEN 1 END) = 0 ) ORDER BY total_runs DESC
@MeanLifeStudies
@MeanLifeStudies 5 дней назад
Have you executed this query?
@MeanLifeStudies
@MeanLifeStudies 5 дней назад
This is second method I had used
@Aditya61515
@Aditya61515 5 дней назад
Thank You a Nice explanation keep going
@MeanLifeStudies
@MeanLifeStudies 5 дней назад
Thank you.
@Vaibha293
@Vaibha293 6 дней назад
amazing bro..
@MeanLifeStudies
@MeanLifeStudies 6 дней назад
Thank You.
@Vaibha293
@Vaibha293 6 дней назад
with cte as( select *,row_number() over(partition by player_id order by match_id)rn from WC_matches) select w.* from WC_players w Join ( select player_id from (select match_id,player_id, case when match_id-lag(match_id,1,match_id-1) over(partition by player_id order by match_id)=1 then 1 else 0 end cont from cte where player_id in (select player_id from cte where rn=3) )A group by player_id having count(player_id)=sum(cont))d on w.id=player_id
@mrsantho
@mrsantho 6 дней назад
with cte1 as( select e.*,e1.empname as managername, e1.salary as managersalary, (e.salary + e1.salary)/2 as averagesalary from employeet1 e join employeet1 e1 on e.mgrid=e1.empid ), cte2 as( select concat(empname,':',managername) as emp_mgr_pair, averagesalary as salary, dense_rank() over(order by averagesalary desc) as rn from cte1 ) select emp_mgr_pair,salary from cte2 where rn=2;
@Vaibha293
@Vaibha293 6 дней назад
WITH CTE AS( SELECT *,SUM(CASE WHEN runs_scored = 0 THEN 0 ELSE 1 END ) OVER (PARTITION BY player_id ORDER BY player_id)DECCOUNT ,COUNT(player_id ) OVER (PARTITION BY player_id ORDER BY player_id)TOTALCOUNT FROM matches) , A AS( SELECT match_id, player_id, runs_scored, SUM(CASE WHEN runs_scored>=50 THEN 1 ELSE 0 END ) OVER (PARTITION BY player_id ORDER BY player_id)TOTAL FROM CTE WHERE DECCOUNT=TOTALCOUNT) SELECT P.name,SUM(runs_scored)TOTALRUNS FROM A JOIN players P ON P.id=A.player_id WHERE TOTAL =2 GROUP BY P.name
@mrsantho
@mrsantho 6 дней назад
with cte_m as (select player_id, count(case when runs_scored >=50 then match_id else null end) as half_century, count(case when runs_scored = 0 then match_id else null end) as duck_out, sum(runs_scored) as total_runs from matches group by player_id), cte_p as( select name,id from players ) select cp.name,cm.total_runs from cte_m cm join cte_p cp on cm.player_id = cp.id where cm.half_century > 1 and cm.duck_out = 0;
@Naveen-uz4hw
@Naveen-uz4hw 6 дней назад
select concat(manager_name,':',b.empname) as emp_mgr_name ,(manager_salary+salary)/2 as salary from (select empid as manager_id ,empname as manager_name ,salary as manager_salary from employee where mgrid is null)a join employee b on a.manager_id=b.mgrid Can you please validate this solution
@MeanLifeStudies
@MeanLifeStudies 6 дней назад
Yes. It is correct. But you are making it too complex. Kindly understand if a manager is not null for Sam then? I mean for Sam is any other manager then?
@VARUNTEJA73
@VARUNTEJA73 7 дней назад
with cte as( select distinct e.empid,t.mgrid,e.empname as mngname,t.empname as empname,e.salary+t.salary as totalsal from employee e join employee t on e.empid=t.mgrid where e.salary<t.salary) select top 1 empname+': '+mngname as emp_mng_pair,totalsal/2 salary from cte order by totalsal desc get employee who are getting highest sal compare to manager then combined two sal and get highest avg sal
@maheshnagisetty4485
@maheshnagisetty4485 7 дней назад
select mgr_emp,avg_sal from ( select *,rank() over(order by avg_sal desc) as rn from ( select concat(e.empname, ':', m.empname) as mgr_emp, (e.salary+m.salary)/2 avg_sal from employee as e join employee as m on e.mgrid=m.empid )as a ) as b where rn=2
@AbhijitPaldeveloper
@AbhijitPaldeveloper 7 дней назад
In your table creation and insertion queries there is no transaction_id column. Please add correct queries
@MeanLifeStudies
@MeanLifeStudies 7 дней назад
Kindly excuse me. In a hurry, I might missed out right SQL statements to write over. I updated that Now. You can see now.
@AbhijitPaldeveloper
@AbhijitPaldeveloper 7 дней назад
My Solution in Mysql: SELECT user_id, total_number, round((total_credit_count*100/total_number),0) as credit_percent, round((total_debit_count*100/total_number),0) as debit_percent FROM(SELECT user_id, COUNT(user_id) as total_number, SUM(CASE WHEN type='credit' THEN 1 ELSE 0 END) as total_credit_count, SUM(CASE WHEN type='debit' THEN 1 ELSE 0 END) as total_debit_count FROM `transactions` GROUP BY user_id) as x;
@AbhijitPaldeveloper
@AbhijitPaldeveloper 7 дней назад
Hi, This is my 2 solutions. 2nd one is similar to your solution. SELECT name FROM(SELECT name, total, DENSE_RANK() OVER(ORDER BY total DESC) as rnk FROM(SELECT e.candidate_id, c.name, COUNT(e.voter_id) as total FROM `election` e join candidates c on e.candidate_id = c.id GROUP BY e.candidate_id) as x) as y WHERE rnk=1; SELECT name FROM(SELECT candidate_id, name, DENSE_RANK() OVER(ORDER BY SUM(voter_value) DESC) as rnk FROM(SELECT e.*, c.name, 1.0/COUNT(e.candidate_id) OVER(PARTITION BY e.voter_id) as voter_value FROM `election` e join candidates c on e.candidate_id = c.id WHERE e.candidate_id IS NOT NULL) as x GROUP BY candidate_id) as y WHERE rnk = 1
@dasubabuch1596
@dasubabuch1596 7 дней назад
Hi Sir, I tried with hierarchical query for this problem. Can you please check it once? with t as ( select empid,empname, prior empname as managername,salary,level from employee start with mgrid = 3 connect by empid = prior mgrid ),t1 as ( select avg(salary) as av_salary from t ) select av_salary, empname||'-'||managername as emp_mgr_pair from t1, t where managername is not null;
@dasubabuch1596
@dasubabuch1596 8 дней назад
Hi Sir, This is my query. with t as ( select e.voter_id,c.id,c.name from election e inner join candidates c on e.candidate_id = c.id where e.candidate_id is not null ),t1 as ( select count(voter_id)over(partition by id) as cnt, voter_id, name, id from t ), t2 as ( select id,name, sum(cnt) as total from t1 group by id,name ), t3 as ( select name, dense_Rank()over(order by total desc) as rnk from t2 ) select name from t3 where rnk = 1;
@maheshnagisetty4485
@maheshnagisetty4485 8 дней назад
select * from ( select *,dense_rank() over( order by cunt desc ) as rn from ( select count(e.voter_id) as cunt,e.candidate_id,c.name from Election as e join candidates as c on e.candidate_id=c.id group by e.candidate_id,c.name ) as a )as b where rn =1
@maheshnagisetty4485
@maheshnagisetty4485 8 дней назад
i tried select player_id, name from ( SELECT *,cunt-rn as diff FROM ( select wm.match_id ,wm.player_id,wm.runs_scored,wp.name, rank() over(partition by player_id order by match_id) as rn,count(*) over(order by player_id) as cunt from WC_matches as wm join WC_players as wp on wm.player_id=wp.id where wm.runs_scored>=50 ) AS A ) as b group by player_id,name having sum(diff)=6
@kushmanthreddy4762
@kushmanthreddy4762 8 дней назад
WITH cte AS ( SELECT player_id, match_id, COUNT(player_id) OVER (PARTITION BY player_id) AS c, ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY match_id) AS rn FROM WC_matches ), ct2 AS ( SELECT player_id, (match_id - rn) AS di FROM cte WHERE c > 2 ), ct3 AS ( SELECT player_id, COUNT(*) OVER (PARTITION BY player_id, di) AS c22 FROM ct2 ) SELECT DISTINCT player_id FROM ct3 WHERE c22 = 3;
@gsrsakhilakhil528
@gsrsakhilakhil528 9 дней назад
group by 2 what is 2 ?
@MeanLifeStudies
@MeanLifeStudies 9 дней назад
Group by 2 or 1 or any number represents group by 2nd column or 1st column......
@gsrsakhilakhil528
@gsrsakhilakhil528 9 дней назад
@@MeanLifeStudies okay sir thank you so much
@AbhijitPaldeveloper
@AbhijitPaldeveloper 10 дней назад
SELECT ym, ROUND(((total - lag(total) OVER(ORDER BY ym ASC))/lag(total) OVER(ORDER BY ym ASC)*100),2) as revenue_diff_pct FROM(SELECT SUM(value) as total, date_format(created_at, '%Y-%m') as ym FROM `sf_transactions` GROUP BY 2) as t;
@omilind
@omilind 10 дней назад
SELECT user_id,count(*) as total_transaction, COUNT(case when type='credit' then Transaction_Id else null end) as total_credit_count, COUNT(case when type='debit' then Transaction_Id else null end) as total_debit_count, CONCAT(SUM(case when type='credit' then 1 else 0 end)*100/count(*),'%') as credit_percentage, CONCAT(SUM(case when type='debit' then 1 else 0 end)*100/count(*),'%') as debit_percentage, from transactions GROUP by user_id order by user_id
@omilind
@omilind 10 дней назад
select p.name as player_name, COUNT(m.runs_scored) half_century from wc_matches as m join wc_players as p on m.player_id=p.id where m.runs_scored>=50 and m.runs_scored<100 GROUP by p.name HAVING count(m.runs_scored)>=3
@khadijasultana8964
@khadijasultana8964 День назад
this will give no of half centuries but not hatrick...you need to find 3 consecutive 50s
@dasubabuch1596
@dasubabuch1596 10 дней назад
Hi Sir, This is my query with t as ( select count(*) as total_txns, user_id from transactions group by user_id ), t1 as ( select user_id, type, count(type)over(partition by user_id, type order by user_id) as count_of_each_type from transactions ), t2 as ( select t1.user_id, t1.type,t.total_txns,t1.count_of_each_type, case when type = 'credit' then (t1.count_of_each_type/t.total_txns)*100 when type = 'debit' then (t1.count_of_each_type/t.total_txns)*100 end as percent from t1 inner join t on t.user_id = t1.user_id ), t3 as ( select user_id, total_txns, count(case when type = 'credit' then percent end) as credit_txns, count(case when type = 'debit' then percent end) as debit_txns from t2 group by user_id, total_txns ) select user_id, total_Txns, (credit_txns/total_Txns)*100 as Credit_Percent, (debit_txns/total_Txns)*100 as debit_Percent from t3;
@dasubabuch1596
@dasubabuch1596 10 дней назад
Hi Sir, Thanks for uploaded the new video. This is my query for this problem. create table transactions ( user_id int, transaction_date date, amount int, type varchar(10) check (type in ('credit', 'debit')) ); insert into transactions values (1, to_date('2024-06-01','yyyy-mm-dd'), 1000, 'credit'); insert into transactions values (2, to_date('2024-06-02','yyyy-mm-dd'), 500, 'debit'); insert into transactions values (1, to_date('2024-06-03','yyyy-mm-dd'), 2000, 'credit'); insert into transactions values (3, to_date('2024-06-04','yyyy-mm-dd'), 1500, 'debit'); insert into transactions values (2, to_date('2024-06-05','yyyy-mm-dd'), 7500, 'credit'); insert into transactions values (4, to_date('2024-06-06','yyyy-mm-dd'), 3000, 'credit'); insert into transactions values (3, to_date('2024-06-07','yyyy-mm-dd'), 1000, 'debit'); insert into transactions values (4, to_date('2024-06-08','yyyy-mm-dd'), 2000, 'debit'); insert into transactions values (5, to_date('2024-06-09','yyyy-mm-dd'), 2500, 'credit'); insert into transactions values (5, to_date('2024-06-10','yyyy-mm-dd'), 500, 'debit'); insert into transactions values (1, to_date('2024-06-11','yyyy-mm-dd'), 4000, 'credit'); insert into transactions values (2, to_date('2024-06-12','yyyy-mm-dd'), 3000, 'debit'); insert into transactions values (3, to_date('2024-06-13','yyyy-mm-dd'), 1000, 'credit'); insert into transactions values (4, to_date('2024-06-14','yyyy-mm-dd'), 1500, 'debit'); insert into transactions values (5, to_date('2024-06-15','yyyy-mm-dd'), 2000, 'credit'); insert into transactions values (1, to_date('2024-06-16','yyyy-mm-dd'), 2500, 'debit'); insert into transactions values (2, to_date('2024-06-17','yyyy-mm-dd'), 2500, 'credit'); insert into transactions values (3, to_date('2024-06-18','yyyy-mm-dd'), 1500, 'debit'); insert into transactions values (4, to_date('2024-06-19','yyyy-mm-dd'), 1000, 'credit'); insert into transactions values (5, to_date('2024-06-20','yyyy-mm-dd'), 3000, 'credit'); */ select * from transactions; with ts as ( select user_id, transaction_Date, amount, type, case when type = 'credit' then amount else -amount end as st from transactions ), t1 as ( select user_id, transaction_Date, amount,type, sum(st)over(partition by user_id order by transaction_date) as total from ts order by transaction_Date ) select user_id, transaction_Date, amount,type,total, case when type = 'credit' then 'eligible' when type = 'debit' and total < 0 then 'ineligible' else 'eligible' end as eligibility from t1;
@MeanLifeStudies
@MeanLifeStudies 10 дней назад
From next on wards please don't paste create and insert statements again. Only share your solution.
@dasubabuch1596
@dasubabuch1596 10 дней назад
@@MeanLifeStudies Sure sir
@karthikvijay5626
@karthikvijay5626 11 дней назад
I really love to solve SQL so i mostly learned and worked in MYSQL only , so if you make vedios in MYSQL it will be useful for me to gain MYSQL knowledge it's my request brother thankyou...
@MeanLifeStudies
@MeanLifeStudies 11 дней назад
Hi, Due to some installation issues i couldn't use MySQL work bench. Remember these queries almost will works in MySQL as well. Just a few syntaxes and system defined functions will be different in MySQL and SQL Server.
@AbhijitPaldeveloper
@AbhijitPaldeveloper 11 дней назад
Question: Which customer has visited the same store location twice for consecutive 2 days and next date shopping amount is higher than previous day In mysql SELECT customer_id, amount FROM(SELECT *, lag(date) OVER(PARTITION BY customer_id, location ORDER BY date ASC) as pre_date, lag(amount) OVER(PARTITION BY customer_id, location ORDER BY date ASC) as pre_amount FROM `shopping`) as e WHERE amount>pre_amount AND DATE_ADD(date, INTERVAL -1 DAY) = pre_date;
@MeanLifeStudies
@MeanLifeStudies 11 дней назад
Not same store. A location has two different stores. So same location.
@AbhijitPaldeveloper
@AbhijitPaldeveloper 11 дней назад
SELECT name, SUM(runs_scored) as runs FROM(SELECT *, SUM(output) OVER(PARTITION BY name) as total_no FROM(SELECT *,CASE WHEN runs_scored < 50 THEN 0 ELSE 1 END as output FROM (SELECT m.match_id, p.name, m.runs_scored FROM `matches` m JOIN players p ON m.player_id = p.id WHERE p.id NOT IN(SELECT id FROM players WHERE id IN(SELECT player_id FROM matches WHERE runs_scored = 0))) as t) as x) as y WHERE total_no >1 GROUP BY name;
@dasubabuch1596
@dasubabuch1596 12 дней назад
Pivot:- ***** select * from ( select product,region,sales from sales )pivot(sum(sales) for Region in ('North' as North,'South' as South,'East' as East) ); Unpivot:- ******* Creating table: --------------- create table sales_Details as select * from ( select product,region,sales from sales )pivot(sum(sales) for Region in ('North' as North,'South' as South,'East' as East) ); select * from sales_Details; Unpivot the above table: ----------------------- select * from (select product,to_char(NORTH) as NORTH, to_char(SOUTH) as SOUTH, to_char(EAST) as EAST FROM sales_Details ) unpivot(column_Val for column_name in (NORTH,SOUTH,EAST));
@dasubabuch1596
@dasubabuch1596 12 дней назад
with qer as ( select m.match_id,m.player_id,m.runs_scored,p.name from wc_matches m inner join wc_players p on m.player_id = p.id where m.runs_scored >= 50 ), ert as ( select q.*, row_number()over(partition by player_id order by match_id) as r from qer q ),hjk as ( select match_id,player_id,runs_Scored,name, match_id-r as f from ert ),uio as ( select match_id,player_id,runs_Scored,name,count(1)over(partition by player_id,f order by player_id) as f from hjk), tip as ( select player_id,f,name, count(*) as cnt from uio group by player_id,f,name having count(*) >= 3), eri as (select player_id, name from tip) select * from eri;
@VARUNTEJA73
@VARUNTEJA73 12 дней назад
with cte as (select match_id-ranks as match_id ,player_id,name from ( select m.match_id,m.player_id,p.name, row_number()over(partition by player_id order by player_id)ranks from wc_matches m join wc_players p on m.player_id=p.id where runs_scored>50 group by match_id,player_id,name)t1) select name from cte group by match_id,player_id,name having count(match_id)=3 Is this right sir?
@MeanLifeStudies
@MeanLifeStudies 12 дней назад
Yes. But avoid complexity.
@VARUNTEJA73
@VARUNTEJA73 12 дней назад
@@MeanLifeStudies ok sir