How to calculate Median in MySQL

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ก.ย. 2024

ความคิดเห็น • 60

  • @zeynepterzi1302
    @zeynepterzi1302 ปีที่แล้ว +3

    I got this quiz on hacker rank and couldn't do it. I searched TH-cam for finding the median mySQL and got to this video and you are solving the same quiz. what a coincidence!

    • @hakaneskici2771
      @hakaneskici2771 6 หลายเดือนก่อน +1

      ben de yapamadım zaten yapamazmışım iyi ki bakmışım

  • @wendyliu9808
    @wendyliu9808 3 ปีที่แล้ว +4

    Sidrah, Thank you so much for making this video! It's very clear and straightforward.

    • @sidrahms7458
      @sidrahms7458  3 ปีที่แล้ว

      Thank you Wendy for the appreciation :) That means a lot to me!!

  • @josephpravin2615
    @josephpravin2615 2 ปีที่แล้ว +2

    Good video! If anyone is wondering why it fails in hackerrank, add round(avg(N.lat_n), 4) in your query

  • @codingstation7741
    @codingstation7741 3 ปีที่แล้ว +2

    Nice! Learnt a lot more about SQL. Thanks

  • @coolpineapple172
    @coolpineapple172 2 ปีที่แล้ว +1

    please explain the significance of @rowindex := -1; I used @rowindex := 0 and got wrong output. how does @rowindex := -1 affects the output?

    • @sidrahms7458
      @sidrahms7458  2 ปีที่แล้ว

      On first iteration it will add 0 to row index, because it will add 1 to row index variable on first iteration which will increment it to 0 from -1

  • @joaquinhernandez3236
    @joaquinhernandez3236 ปีที่แล้ว +2

    Don't forget to round it up to 4 decimal places. The full correct answer would look like this:
    SET @rowindex:=-1;
    SELECT ROUND(AVG(N.LAT_N), 4)
    FROM (SELECT @rowindex:=@rowindex +1 AS rowindex,
    STATION.LAT_N AS LAT_N
    FROM STATION
    ORDER BY STATION.LAT_N) AS N
    WHERE N.rowindex IN (FLOOR(@rowindex/2), CEIL(@rowindex/2));

  • @dondedios1562
    @dondedios1562 5 หลายเดือนก่อน

    Thank you very much, greetings from Argentina!

  • @fazal179
    @fazal179 ปีที่แล้ว

    made my day sidra thanku so much i am beginner this helped me a lot

    • @sidrahms7458
      @sidrahms7458  ปีที่แล้ว

      Happy to help 😀

    • @fazal179
      @fazal179 ปีที่แล้ว

      @@sidrahms7458 hey I am confused in lots of concepts of working but you video made my day ...just asking ... exactly form where should I practice and learn SQL is there any specific source..?

    • @fazal179
      @fazal179 ปีที่แล้ว

      I will be very grateful if you will tell me 😊..?

    • @sidrahms7458
      @sidrahms7458  ปีที่แล้ว

      @@fazal179 𝐏𝐫𝐞𝐩𝐚𝐫𝐚𝐭𝐢𝐨𝐧 𝐩𝐥𝐚𝐧 𝐟𝐨𝐫 15 𝐝𝐚𝐲𝐬 𝐭𝐨 𝐛𝐫𝐮𝐬𝐡 𝐮𝐩 𝐨𝐧 𝐒𝐐𝐋 𝐬𝐤𝐢𝐥𝐥𝐬.
      𝐃𝐚𝐲 1-2: 𝐑𝐞𝐟𝐫𝐞𝐬𝐡 𝐒𝐐𝐋 𝐛𝐚𝐬𝐢𝐜𝐬 𝐚𝐧𝐝 𝐬𝐲𝐧𝐭𝐚𝐱
      SQL tutorial on W3Schools (lnkd.in/guyumWHy)
      SQL tutorial on Mode Analytics (lnkd.in/gsYkbCgn)
      𝐃𝐚𝐲 3-5: 𝐌𝐚𝐬𝐭𝐞𝐫 𝐒𝐐𝐋 𝐪𝐮𝐞𝐫𝐢𝐞𝐬 𝐚𝐧𝐝 𝐝𝐚𝐭𝐚 𝐦𝐚𝐧𝐢𝐩𝐮𝐥𝐚𝐭𝐢𝐨𝐧
      SQL Zoo (sqlzoo.net/)
      HackerRank SQL Practice (lnkd.in/gRh4w4Kb)
      𝐃𝐚𝐲 6-8: 𝐋𝐞𝐚𝐫𝐧 𝐚𝐝𝐯𝐚𝐧𝐜𝐞𝐝 𝐒𝐐𝐋 𝐜𝐨𝐧𝐜𝐞𝐩𝐭𝐬
      SQL window functions tutorial on Mode Analytics (lnkd.in/gjnFxuHg)
      SQL aggregation functions tutorial on Mode Analytics (lnkd.in/gqTJ-vAp)
      𝐃𝐚𝐲 9-11: 𝐖𝐨𝐫𝐤 𝐨𝐧 𝐫𝐞𝐚𝐥-𝐰𝐨𝐫𝐥𝐝 𝐒𝐐𝐋 𝐩𝐫𝐨𝐛𝐥𝐞𝐦𝐬
      LeetCode SQL Problems (lnkd.in/gWpmp-fN)
      SQL Practice Problems (lnkd.in/gjCWYafQ)
      𝐃𝐚𝐲 12-13: 𝐏𝐫𝐚𝐜𝐭𝐢𝐜𝐞 𝐒𝐐𝐋 𝐰𝐢𝐭𝐡 𝐬𝐚𝐦𝐩𝐥𝐞 𝐝𝐚𝐭𝐚𝐬𝐞𝐭𝐬
      Kaggle Datasets (lnkd.in/gEDAjmpa)
      SQLite Tutorial on Tutorialspoint (lnkd.in/gXz8tyJp)
      𝐃𝐚𝐲 14-15: 𝐑𝐞𝐯𝐢𝐞𝐰 𝐚𝐧𝐝 𝐫𝐞𝐟𝐢𝐧𝐞 𝐲𝐨𝐮𝐫 𝐒𝐐𝐋 𝐬𝐤𝐢𝐥𝐥𝐬
      SQL Exercises for Data Analysis (lnkd.in/gQ9CtucP)
      SQL interview questions on Interview Query (lnkd.in/gqgNtkvt)
      Remember to practice consistently every day and review your progress regularly. Good luck with your SQL preparation!
      Kaggle W3Schools.com HackerRank Sqlzoo.Cn Lee

    • @sidrahms7458
      @sidrahms7458  ปีที่แล้ว

      These are just some reference links, and are not meant to be completed in 15 days, take your time, but practice daily at least one problem after reading theoretical syntax and working, hope this helps......

  • @joannwatu7603
    @joannwatu7603 3 ปีที่แล้ว +1

    Thank you so much for this video. It helped me clear up my confusion.

  • @aadityaagrawal11
    @aadityaagrawal11 3 ปีที่แล้ว +2

    THANK YOU VERY MUCH

    • @sidrahms7458
      @sidrahms7458  3 ปีที่แล้ว

      Welcome, glad I could help! :)

  • @supriya1316
    @supriya1316 2 ปีที่แล้ว +1

    Thanks a lot !

  • @muhammadkhalidhasan6291
    @muhammadkhalidhasan6291 ปีที่แล้ว

    Best solution ..make more videos it was very helpful for me

  • @supriya1316
    @supriya1316 2 ปีที่แล้ว +1

    Please make video on other Hackerrank sql problems as well. Explained very well !

  • @tejasai3590
    @tejasai3590 3 ปีที่แล้ว +1

    Thanks Alot! This was really helpful.

    • @sidrahms7458
      @sidrahms7458  3 ปีที่แล้ว +1

      Thanks for the appreciation, means a lot to me 🙂

  • @pratiksingh9480
    @pratiksingh9480 2 ปีที่แล้ว +1

    Explained really well !

  • @jaiicheung8225
    @jaiicheung8225 2 ปีที่แล้ว

    thank you for explaning! super easy to understand following the steps.

  • @codingwithbobby
    @codingwithbobby 3 ปีที่แล้ว +1

    awesome explanation thanks for posting it.

    • @sidrahms7458
      @sidrahms7458  3 ปีที่แล้ว

      Thank you Priyanshu!! Your encouragement means a lot to me!

  • @safakhan7960
    @safakhan7960 2 ปีที่แล้ว

    Second question, what is the use of colon while setting the variable,
    Because whenever I am removing the colon it affects the decimal values ...

  • @aikenlee1060
    @aikenlee1060 3 ปีที่แล้ว +1

    Great explanation and pictorial

  • @safakhan7960
    @safakhan7960 2 ปีที่แล้ว

    Just 1 ques , I think the variable are declared by delcare statement, then why u r using the set command , kindly explain...

  • @Mr.X-ur1we
    @Mr.X-ur1we 10 หลายเดือนก่อน

    clear explaination

  • @mukeshkumar-kh2fh
    @mukeshkumar-kh2fh 2 ปีที่แล้ว

    thank you mam plz make all these video

  • @mikecwikielnik4852
    @mikecwikielnik4852 ปีที่แล้ว

    great work

  • @rohanbhandari7796
    @rohanbhandari7796 3 ปีที่แล้ว +1

    Thanks

  • @afreenahmed3952
    @afreenahmed3952 3 ปีที่แล้ว +1

    Why do we need to set the column in ascending or descending order?

    • @sidrahms7458
      @sidrahms7458  3 ปีที่แล้ว +3

      @Afreen Ahmed Because median is a middle value taken from an ordered list of element/members, you cannot take median from an arbitrary list of elements, you need to first order it (in other words sort it) and then find the middle number that falls in that ordered list. Hope this answers your question. Please let me know if you have any further questions.

    • @afreenahmed3952
      @afreenahmed3952 3 ปีที่แล้ว

      @@sidrahms7458 thanks a lot.. That's all from me😊

  • @dondedios1562
    @dondedios1562 5 หลายเดือนก่อน

    You're fucking genius, thank you

  • @nithinma8697
    @nithinma8697 3 ปีที่แล้ว

    This was helpful.

    • @sidrahms7458
      @sidrahms7458  3 ปีที่แล้ว

      Thanks for the appreciation Nithin

  • @AnkitThakur-vq5xb
    @AnkitThakur-vq5xb ปีที่แล้ว

    why sett rowindex as -1?

    • @sidrahms7458
      @sidrahms7458  ปีที่แล้ว

      On first iteration it will add 0 to row index, because it will add 1 to row index variable on first iteration which will increment it to 0 from -1

  • @ujjwalkumar8173
    @ujjwalkumar8173 3 ปีที่แล้ว

    Thank you so much for this quality content!!

    • @sidrahms7458
      @sidrahms7458  3 ปีที่แล้ว +1

      Thank you Ujjwal for the appreciation :) Please don't forget to subscribe to my channel I am planning more content to upload in the future.

    • @ujjwalkumar8173
      @ujjwalkumar8173 3 ปีที่แล้ว

      @@sidrahms7458 Subscribed!! Your way of teaching is too good.. Keep making videos..

  • @ujjwalkumar8173
    @ujjwalkumar8173 3 ปีที่แล้ว +1

    Can you please tell the use of '@'

    • @sidrahms7458
      @sidrahms7458  3 ปีที่แล้ว +2

      Hi Ujjwal, to create a user-defined variable in MySQL, you use the format @variable_name, where the variable_name consists of alphanumeric characters. The maximum length of the user-defined variable is 64 characters as of MySQL 5.7.5. Hope this answers your question, please let me know if you have more questions regarding this, thanks :)

    • @ujjwalkumar8173
      @ujjwalkumar8173 3 ปีที่แล้ว +1

      @@sidrahms7458 Yeah that was helpful.. One more thing :) inside FLOOR and CEIL we are using that variable.. Just writing the column name i.e. rowindex instead of @rowindex is giving different answer.. Can you highlight the reason behind using @ inside these functions.

    • @sidrahms7458
      @sidrahms7458  3 ปีที่แล้ว

      What is the answer you are getting when you use rowindex instead of @rowindex?

    • @ujjwalkumar8173
      @ujjwalkumar8173 3 ปีที่แล้ว

      @@sidrahms7458 using (CEIL(rowindex/2),FLOOR(rowindex/2)) is giving 25.2409
      while using (CEIL(@rowindex/2),FLOOR(@rowindex/2)) is giving 83.8913 that is the correct one..

  • @AnkitSharma-sp3fs
    @AnkitSharma-sp3fs 3 ปีที่แล้ว

    Hi mentor, understand the answer but this code doesn't not work on hackerank and given output is null, please check and verify 👍

    • @sidrahms7458
      @sidrahms7458  3 ปีที่แล้ว

      Please post your code here so that I can verify, I want to check if there is difference in your and my code

    • @AnkitSharma-sp3fs
      @AnkitSharma-sp3fs 3 ปีที่แล้ว

      @@sidrahms7458 I did exactly which you did in hackerank but now showing null output

    • @sidrahms7458
      @sidrahms7458  3 ปีที่แล้ว +1

      @@AnkitSharma-sp3fs Please check this video, the solution works I just tested it again: th-cam.com/video/Jiqp55ZWrJY/w-d-xo.html, please try using the code I have mentioned in the description of this video, also compare how my code is different from yours to understand where you are making mistake, let me know if this solves your issue.

  • @bhatnagaraki
    @bhatnagaraki 2 ปีที่แล้ว

    Abe Jaldi bol subh Panvel nikalna hai.

    • @sidrahms7458
      @sidrahms7458  2 ปีที่แล้ว +3

      You do know that TH-cam offers video speed increase option right???

  • @karlamarianarosasjimenez1452
    @karlamarianarosasjimenez1452 2 ปีที่แล้ว +1

    Thank you so much!!