How to Calculate Mode in SQL | How to Find Most Frequent Value in a Column

  Рет қаралды 17,176

Ankit Bansal

Ankit Bansal

2 жыл бұрын

In this video we will learn 2 methods of how to calculate mode in SQL.
First method will be using pure CTE. Second method will be using Rank function.
Mode is nothing but most frequent value in an Array.
create table mode
(
id int
);
insert into mode values (1),(2),(2),(3),(3),(3),(3),(4),(5);
SQL basics | how to find mode | sql interview questions

Пікірлер: 32
@shaktijyoti4553
@shaktijyoti4553 2 жыл бұрын
Thanks Brother for your precise explanation,though I had the knowledge about joins still I got some useful insights.
@divyaaggarwal7824
@divyaaggarwal7824 2 жыл бұрын
I am preparing for interviews and I just came across your channel. The videos are really informative. Thankyou so much !! 👍🏻 Keep up the good work, buddy.
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Thank you 😊
@kanchankumar3355
@kanchankumar3355 2 жыл бұрын
Much helpful! Thanks for putting it up
@ankitbansal6
@ankitbansal6 2 жыл бұрын
🙏
@sanjeetsingh1406
@sanjeetsingh1406 2 жыл бұрын
Great solutions in simple way. I would like to share my interview experience.. This was the 1st questions asked in OPTUM(UHG) interview.. both using SQL & Tableau .. @Ankit your videos are really very helpfull in clearing concepts & basics .. keep up the good work :)
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Thank you 😊
@mohammadabdullahansari6314
@mohammadabdullahansari6314 Жыл бұрын
For which role?
@anishchhabra6085
@anishchhabra6085 7 ай бұрын
Excellent explanation bro! I think instead of 2 cte's we can use this code with cte as ( select *, rank() over(order by count(id) desc) as rnk from mode group by id ) select id from cte where rnk = 1;
@ankitbansal6
@ankitbansal6 7 ай бұрын
Great 👍
@Msd.....792
@Msd.....792 Жыл бұрын
Great explanation sir, I have also solved it but using subquery and rank function without CTE
@ankitbansal6
@ankitbansal6 Жыл бұрын
Cool
@anujgupta8686
@anujgupta8686 2 жыл бұрын
with cte as( select id, row_number() over (partition by id order by id) most_time from mode) select * from cte where most_time = (select max(most_time) from cte)
@yosupalex8276
@yosupalex8276 Жыл бұрын
I'm thinking about using row_number() as well because there will only be only one record in output this way
@akashsaini704
@akashsaini704 Жыл бұрын
thank you
@themightyvk
@themightyvk 11 ай бұрын
Thanks
@Mysingh9767
@Mysingh9767 2 жыл бұрын
Thanks... Great video
@ankitbansal6
@ankitbansal6 2 жыл бұрын
🙏
@neelshah8803
@neelshah8803 2 жыл бұрын
Can you please make videos on python and ML
@godslavepreet
@godslavepreet 2 жыл бұрын
Good Ankit
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Thank you 😊
@soumyagobbani5336
@soumyagobbani5336 Жыл бұрын
cte as (select id, rank() over (order by count(*) desc) rwn from mode group by id) select * from cte where rwn =1
@vishalsonawane.8905
@vishalsonawane.8905 3 ай бұрын
Done
@vijaypalmanit
@vijaypalmanit 2 жыл бұрын
With you sql seems piece of cake
@ankitbansal6
@ankitbansal6 2 жыл бұрын
It is piece of cake if you understand fundamentals 😊
@CloudDataEngineer
@CloudDataEngineer 2 жыл бұрын
;WITH cte AS (SELECT id, RANK() OVER (ORDER BY COUNT(id) DESC) AS RNK FROM dbo.mode GROUP BY id) SELECT id FROM cte WHERE RNK = 1;
@grim_rreaperr
@grim_rreaperr Жыл бұрын
SELECT TOP 1 WITH TIES *,COUNT(1) AS frequency FROM mode GROUP BY id ORDER BY COUNT(1) DESC;
@armanmardhani8963
@armanmardhani8963 Жыл бұрын
select id, count(id) as occurrences from modes group by id having count(id) = (select max(count(id)) from modes group by id) How about this?
@prabhatgupta6415
@prabhatgupta6415 Жыл бұрын
with cte as (select id,count(*)as m from mode1 group by id order by M desc) select id,M from cte where M=(select max(M) from cte)
@user-no5mt8jw9q
@user-no5mt8jw9q 11 ай бұрын
Here is my Code: select top 1 id, count(*) as Frequency from mode group by id order by count(*) desc
@GiriPrasath.D
@GiriPrasath.D 4 ай бұрын
select top 1 id, count(*) as Frequency from mode group by id order by frequency desc
IQ Level: 10000
00:10
Younes Zarou
Рет қаралды 6 МЛН
Amazing weight loss transformation !! 😱😱
00:24
Tibo InShape
Рет қаралды 62 МЛН
What it feels like cleaning up after a toddler.
00:40
Daniel LaBelle
Рет қаралды 84 МЛН
Sql select most repeated value
6:46
kudvenkat
Рет қаралды 95 М.
Advanced Aggregate Functions in SQL (GROUP BY, HAVING vs. WHERE)
6:00
Becoming a Data Scientist
Рет қаралды 240 М.
SQL Joins - Beginner to PRO Masterclass with 10 Examples
27:08
Find Outliers in SQL
8:58
Absent Data
Рет қаралды 10 М.
SQL Query | How to dynamically convert rows into columns | Dynamic Pivot
16:18
6 SQL Joins you MUST know! (Animated + Practice)
9:47
Anton Putra
Рет қаралды 129 М.
Проверил, как вам?
0:58
Коннор
Рет қаралды 147 М.
КРУТОЙ ТЕЛЕФОН
0:16
KINO KAIF
Рет қаралды 6 МЛН
Samsung laughing on iPhone #techbyakram
0:12
Tech by Akram
Рет қаралды 6 МЛН
low battery 🪫
0:10
dednahype
Рет қаралды 1,3 МЛН
iPhone 15 Pro Max vs IPhone Xs Max  troll face speed test
0:33
Looks very comfortable. #leddisplay #ledscreen #ledwall #eagerled
0:19
LED Screen Factory-EagerLED
Рет қаралды 6 МЛН