This is personal study note Copyright and original reference: https://www.youtube.com/watch?v=7UpsG6_HoI0&list=PLVsNizTWUw7HhYtI-4GGmlJ5yxNdwNI_X ================================================================================ You should keep the order or sentence (from -> where -> group by -> having -> order by) ================================================================================ BBK --> 5+10+2+2=19 product is purchased by BBK To simplify that task, you can use "group by" - group by, and then perform sum(amount) "group by" is useful ================================================================================ Use AS (alias) ================================================================================ ================================================================================ ================================================================================ ================================================================================ ================================================================================ ================================================================================ ================================================================================ ================================================================================ ================================================================================ ================================================================================ where can't be used along with "group functions" when you use "group function", use "having" for condition instead of "where" ================================================================================ Rollup