MySQL: GROUP BY

Поделиться
HTML-код
  • Опубликовано: 19 июн 2024
  • #MySQL #tutorial #course
    You can copy and paste all of the following statements if you would like to follow along in this video.
    P.S. Make sure you have a customers table if you're linking the foreign key on customer_id.
    ------------------------------------------------------------
    DROP TABLE IF EXISTS transactions;
    CREATE TABLE transactions (
    transaction_id INT PRIMARY KEY AUTO_INCREMENT,
    amount DECIMAL(5, 2),
    customer_id INT,
    order_date DATE,
    FOREIGN KEY (customer_id)
    REFERENCES customers(customer_id)
    );
    INSERT INTO transactions
    VALUES (1000, 4.99, 3, "2023-01-01"),
    (1001, 2.89, 2, "2023-01-01"),
    (1002, 3.38, 3, "2023-01-02"),
    (1003, 4.99, 1, "2023-01-02"),
    (1004, 1.00, NULL, "2023-01-03"),
    (1005, 2.49, 4, "2023-01-03"),
    (1006, 5.48, NULL, "2023-01-03");
    SELECT * FROM transactions;
    ------------------------------------------------------------
    00:00:00 intro
    00:00:16 data for this demo
    00:00:00 GROUP BY
    00:03:19 HAVING
    00:04:36 conclusion

Комментарии • 36

  • @BroCodez
    @BroCodez  Год назад +10

    You can copy and paste all of the following statements if you would like to follow along in this video.
    P.S. Make sure you have a customers table if you're linking the foreign key on customer_id.
    ------------------------------------------------------------
    DROP TABLE IF EXISTS transactions;
    CREATE TABLE transactions (
    transaction_id INT PRIMARY KEY AUTO_INCREMENT,
    amount DECIMAL(5, 2),
    customer_id INT,
    order_date DATE,
    FOREIGN KEY (customer_id)
    REFERENCES customers(customer_id)
    );
    INSERT INTO transactions
    VALUES (1000, 4.99, 3, "2023-01-01"),
    (1001, 2.89, 2, "2023-01-01"),
    (1002, 3.38, 3, "2023-01-02"),
    (1003, 4.99, 1, "2023-01-02"),
    (1004, 1.00, NULL, "2023-01-03"),
    (1005, 2.49, 4, "2023-01-03"),
    (1006, 5.48, NULL, "2023-01-03");

    SELECT * FROM transactions;
    ------------------------------------------------------------
    -- EXAMPLE 1 --
    SELECT SUM(amount), order_date
    FROM transactions
    GROUP BY order_date;
    -- EXAMPLE 2 --
    SELECT COUNT(amount), customer_id
    FROM transactions
    GROUP BY customer_id
    HAVING COUNT(amount) > 1 AND customer_id IS NOT NULL;

  • @youneverknew_me
    @youneverknew_me Год назад +15

    I've read the article about GROUP BY but still don't understand. Your explanation is simply the best!

  • @zabehullahalizadeh2310
    @zabehullahalizadeh2310 Год назад +5

    I love your voice and the way that you teach us. Thank you Bro Code

  • @lordofdeath9247
    @lordofdeath9247 11 месяцев назад +2

    bro you are a treasure , thank you for existing

  • @ned7757
    @ned7757 Год назад

    Your videos have really helped me. I really appreciate it!

  • @abundance2616
    @abundance2616 9 месяцев назад +1

    Thanks a lot for explaining it so nicely

  • @APDesignFXP
    @APDesignFXP Год назад +7

    Dude couldn’t have a better timing i just got my assignment in sql

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

    FINALLY an explanation that i understand. Thanks!

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

    Thank you, great explanation

  • @celineharakee
    @celineharakee Год назад

    life saver, I owe u my life

  • @DarkSoulGaming7
    @DarkSoulGaming7 Год назад

    Love from TN too , India!

  • @offlinemoe
    @offlinemoe 11 месяцев назад +1

    Thank you, it helped me a lot

  • @Blizz-rm6ec
    @Blizz-rm6ec Месяц назад

    thank you i have an asessment tomorrow it helped a lot

  • @keroro3187
    @keroro3187 Год назад

    Thank you very much

  • @maisie2735
    @maisie2735 5 месяцев назад

    THANK YOU 😭

  • @YoshiGG_
    @YoshiGG_ 6 месяцев назад

    thank you brocode Another day Another Victory for the ogs

  • @olufemiolawale3848
    @olufemiolawale3848 11 месяцев назад

    Well explained.

  • @gabrielodiase7357
    @gabrielodiase7357 11 месяцев назад

    God bless you bro

  • @MDMushu-ff5od
    @MDMushu-ff5od 14 дней назад

    Just like wowww

  • @Personal1123-et3bb
    @Personal1123-et3bb Месяц назад

    Thanks

  • @alamzia2905
    @alamzia2905 7 месяцев назад

    what a top notch explanation sir.

  • @stanhe9922
    @stanhe9922 24 дня назад

    u the goat

  • @israelcyrus2586
    @israelcyrus2586 Год назад +1

    love u bro from Tamilnadu.

  • @ilijapopovic1826
    @ilijapopovic1826 Год назад

    Love you bro

  • @pravinv_
    @pravinv_ 8 месяцев назад +2

    we can use where Clause also.
    Give the Where clause above the GroupBy Clause.But for Aggregate functions we need to use Having within Groupby

  • @mdfaisalmahamud
    @mdfaisalmahamud Год назад

    Love From Bangladesh 🇧🇩

  • @hackerexploit8957
    @hackerexploit8957 Год назад +1

    Please make a bash & powershell series too 😊

  • @shawnchristophermalig4339
    @shawnchristophermalig4339 7 месяцев назад

    Can you make a video, explaining the math or innerworkings of GROUP by? I think what others seemed to get confused about group by is the fact that the math isn't mathin'.
    I mean that you visualize select, but it's hard to visualize into thinking the group by. :)
    Questions like: is it correct that 2 invisible became a pattern marker for group by? Something like that! 😁

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

    THANK YOU SO MUCH AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

  • @itz_phil5146
    @itz_phil5146 Год назад

    Are you able to do more videos about javaFX?

  • @QURAN_010
    @QURAN_010 9 месяцев назад

    I like your voice bro *_^

  • @vaibhavsinhbihola1
    @vaibhavsinhbihola1 6 месяцев назад

    Hey I am also using MySQL workbench mine text editor is not same as you how I can changed it to dark and like you

  • @shortsShowcase250
    @shortsShowcase250 9 месяцев назад

    Can we use DISTINCT instead of GROUP BY

  • @sidneywolfe9260
    @sidneywolfe9260 Год назад

    𝓅𝓇𝑜𝓂𝑜𝓈𝓂

  • @reema5315
    @reema5315 29 дней назад

    Would you marry me?

  • @fredianriko5648
    @fredianriko5648 11 месяцев назад

    could you please share the sql dump so we could also practice with the exact data you have?