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;
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! 😁
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;
I've read the article about GROUP BY but still don't understand. Your explanation is simply the best!
This video explained it so much better than the first one I saw, thank you.
bro you are a treasure , thank you for existing
I love your voice and the way that you teach us. Thank you Bro Code
FINALLY an explanation that i understand. Thanks!
You are a god much love from IT student from serbia
Dude couldn’t have a better timing i just got my assignment in sql
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
Thanks a lot for explaining it so nicely
Thank you, great explanation
love u bro from Tamilnadu.
what a top notch explanation sir.
thank you brocode Another day Another Victory for the ogs
Love From Bangladesh 🇧🇩
Your videos have really helped me. I really appreciate it!
thank you i have an asessment tomorrow it helped a lot
I love you, thank you 😭😭
Thank you, it helped me a lot
life saver, I owe u my life
Having clause can be used as a substitute for the where clause, in case we are using group by clause.
Just like wowww
you are the best
Love from TN too , India!
THANK YOU SO MUCH AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Well explained.
THANK YOU 😭
u the goat
Thank you very much
God bless you bro
Thanks
Please make a bash & powershell series too 😊
Love you bro
Are you able to do more videos about javaFX?
I like your voice bro *_^
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! 😁
Can we use DISTINCT instead of GROUP BY
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
𝓅𝓇𝑜𝓂𝑜𝓈𝓂
Would you marry me?
could you please share the sql dump so we could also practice with the exact data you have?