My SQL: GROUP BY
, 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 customerid. DROP TABLE IF EXISTS transactions; CREATE TABLE transactions ( transactionid INT PRIMARY KEY AUTOINCREMENT, amount DECIMAL(5, 2), customerid INT, orderdate DATE, FOREIGN KEY (customerid) REFERENCES customers(customerid) ); INSERT INTO transactions VALUES (1000, 4. 99, 3, 20230101 ), (1001, 2. 89, 2, 20230101 ), (1002, 3. 38, 3, 20230102 ), (1003, 4. 99, 1, 20230102 ), (1004, 1. 00, NULL, 20230103 ), (1005, 2. 49, 4, 20230103 ), (1006, 5. 48, NULL, 20230103 ); 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
|