MySQL Forums
Forum List  »  MySQL Workbench

Re: GROUP BY is Broken?
Posted by: Kevin Wood Wood
Date: February 19, 2022 09:07AM

Sorry... already removed SUM in previous code:

Drop database if exists test;
Create Database test;
use test;
DROP TABLE if exists test_table ;

CREATE TABLE test_table (
BU varchar(15),
BU_Name VARCHAR(25),
Product VARCHAR(25),
Region VARCHAR(25),
Year INT,
Month Int,
Sum Int,
Total Int
);

INSERT INTO Test_Table (BU, BU_Name, Product, Region, Year, Month, Sum, Total)
VALUES
('Growth','Energy','Purple Pain','Midwest','2017','3','27','2835'),
('Growth','Energy','Purple Pain','Midwest','2017','8','34','3570'),
('Growth','Energy','Purple Pain','Midwest','2017','12','66','6930'),
('Growth','Energy','Purple Pain','Midwest','2018','1','131','13755'),
('Growth','Energy','Purple Pain','Midwest','2018','6','125','13125'),
('Growth','Energy','Purple Pain','Midwest','2018','12','80','8400'),
('Growth','Energy','Purple Pain','Midwest','2018','12','129','13545'),
('Growth','Energy','Purple Pain','Midwest','2019','6','96','9072'),
('Growth','Energy','Purple Pain','Midwest','2019','9','68','7140'),
('Growth','Energy','Purple Pain','Midwest','2019','11','12','1260'),
('Growth','Energy','Purple Pain','Midwest','2019','12','65','6825'),
('Growth','Energy','Purple Pain','Northeast','2017','3','7','735'),
('Growth','Energy','Purple Pain','Northeast','2017','8','44','4620'),
('Growth','Energy','Purple Pain','Northeast','2018','4','101','10605'),
('Growth','Energy','Purple Pain','Northeast','2018','11','55','5775'),
('Growth','Energy','Purple Pain','Northeast','2019','3','3','315'),
('Growth','Energy','Purple Pain','South','2017','4','1','105'),
('Growth','Energy','Purple Pain','South','2017','4','54','5670'),
('Growth','Energy','Purple Pain','South','2017','6','89','9345'),
('Growth','Energy','Purple Pain','South','2017','10','71','7455'),
('Growth','Energy','Purple Pain','South','2017','11','14','1470'),
('Growth','Energy','Purple Pain','South','2017','11','23','2415'),
('Growth','Energy','Purple Pain','South','2017','12','14','1470'),
('Growth','Energy','Purple Pain','South','2018','1','58','6090'),
('Growth','Energy','Purple Pain','South','2018','3','18','1890'),
('Growth','Energy','Purple Pain','South','2018','3','117','12285'),
('Growth','Energy','Purple Pain','South','2018','3','138','14490'),
('Growth','Energy','Purple Pain','South','2018','3','143','15015'),
('Growth','Energy','Purple Pain','South','2018','5','125','13125'),
('Growth','Energy','Purple Pain','South','2018','6','81','8505'),
('Growth','Energy','Purple Pain','South','2018','12','154','16170'),
('Growth','Energy','Purple Pain','South','2019','4','44','4620'),
('Growth','Energy','Purple Pain','South','2019','7','4','420'),
('Growth','Energy','Purple Pain','South','2019','7','23','2415'),
('Growth','Energy','Purple Pain','South','2019','7','37','3885'),
('Growth','Energy','Purple Pain','South','2019','7','41','4305'),
('Growth','Energy','Purple Pain','South','2019','7','77','8085'),
('Growth','Energy','Purple Pain','South','2019','8','12','1260'),
('Growth','Energy','Purple Pain','South','2019','11','79','8295'),
('Growth','Energy','Purple Pain','South','2019','11','86','9030'),
('Growth','Energy','Purple Pain','South','2019','12','38','3990'),
('Growth','Energy','Purple Pain','West','2017','1','86','9030'),
('Growth','Energy','Purple Pain','West','2017','2','93','9765'),
('Growth','Energy','Purple Pain','West','2017','6','3','315'),
('Growth','Energy','Purple Pain','West','2017','8','7','735'),
('Growth','Energy','Purple Pain','West','2017','11','5','525'),
('Growth','Energy','Purple Pain','West','2017','11','65','6825'),
('Growth','Energy','Purple Pain','West','2018','1','159','16695'),
('Growth','Energy','Purple Pain','West','2018','3','102','10710'),
('Growth','Energy','Purple Pain','West','2018','5','129','13545'),
('Growth','Energy','Purple Pain','West','2018','8','94','9870'),
('Growth','Energy','Purple Pain','West','2018','8','168','17640'),
('Growth','Energy','Purple Pain','West','2018','10','98','10290'),
('Growth','Energy','Purple Pain','West','2019','3','60','6300'),
('Growth','Energy','Purple Pain','West','2019','3','66','6930'),
('Growth','Energy','Purple Pain','West','2019','7','24','2520'),
('Growth','Energy','Purple Pain','West','2019','9','17','1785'),
('Growth','Energy','Purple Pain','West','2019','10','6','630'),
('Growth','Energy','Purple Pain','West','2019','10','9','945'),
('Growth','Energy','Purple Pain','West','2019','12','91','8599'),
('Growth','Energy','Red Hot Chili Peppers','Midwest','2017','2','64','14912'),
('Growth','Energy','Red Hot Chili Peppers','Midwest','2017','4','93','21669'),
('Growth','Energy','Red Hot Chili Peppers','Midwest','2017','5','32','7456'),
('Growth','Energy','Red Hot Chili Peppers','Midwest','2017','5','94','21902'),
('Growth','Energy','Red Hot Chili Peppers','Midwest','2018','1','94','21902'),
('Growth','Energy','Red Hot Chili Peppers','Midwest','2018','6','74','17242'),
('Growth','Energy','Red Hot Chili Peppers','Midwest','2018','6','180','41940'),
('Growth','Energy','Red Hot Chili Peppers','Midwest','2018','12','128','29824'),
('Growth','Energy','Red Hot Chili Peppers','Midwest','2019','1','12','2796'),
('Growth','Energy','Red Hot Chili Peppers','Midwest','2019','1','49','11417'),
('Growth','Energy','Red Hot Chili Peppers','Midwest','2019','2','82','19106'),
('Growth','Energy','Red Hot Chili Peppers','Midwest','2019','4','44','10252'),
('Growth','Energy','Red Hot Chili Peppers','Midwest','2019','10','77','17941'),
('Growth','Energy','Red Hot Chili Peppers','Northeast','2017','3','87','20271'),
('Growth','Energy','Red Hot Chili Peppers','Northeast','2017','4','77','17941'),
('Growth','Energy','Red Hot Chili Peppers','Northeast','2017','9','12','2796'),
('Growth','Energy','Red Hot Chili Peppers','Northeast','2018','5','130','30290'),
('Growth','Energy','Red Hot Chili Peppers','Northeast','2018','12','63','14679'),
('Growth','Energy','Red Hot Chili Peppers','Northeast','2019','1','20','4660'),
('Growth','Energy','Red Hot Chili Peppers','Northeast','2019','11','67','15611'),
('Growth','Energy','Red Hot Chili Peppers','Northeast','2019','12','17','3961'),
('Growth','Energy','Red Hot Chili Peppers','South','2017','1','23','5359'),
('Growth','Energy','Red Hot Chili Peppers','South','2017','4','82','19106'),
('Growth','Energy','Red Hot Chili Peppers','South','2017','5','44','10252'),
('Growth','Energy','Red Hot Chili Peppers','South','2017','7','11','2563'),
('Growth','Energy','Red Hot Chili Peppers','South','2018','1','153','35649'),
('Growth','Energy','Red Hot Chili Peppers','South','2018','1','159','37047'),
('Growth','Energy','Red Hot Chili Peppers','South','2018','5','45','10485'),
('Growth','Energy','Red Hot Chili Peppers','South','2018','6','162','37746'),
('Growth','Energy','Red Hot Chili Peppers','South','2018','10','155','36115'),
('Growth','Energy','Red Hot Chili Peppers','South','2019','1','24','5592'),
('Growth','Energy','Red Hot Chili Peppers','South','2019','5','57','13281'),
('Growth','Energy','Red Hot Chili Peppers','South','2019','9','59','13747'),
('Growth','Energy','Red Hot Chili Peppers','South','2019','10','68','15844'),
('Growth','Energy','Red Hot Chili Peppers','West','2017','1','42','9786'),
('Growth','Energy','Red Hot Chili Peppers','West','2017','2','36','8388'),
('Growth','Energy','Red Hot Chili Peppers','West','2017','10','9','2097'),
('Growth','Energy','Red Hot Chili Peppers','West','2017','11','87','20271'),
('Growth','Energy','Red Hot Chili Peppers','West','2017','12','39','9087'),
('Growth','Energy','Red Hot Chili Peppers','West','2018','2','57','13281'),
('Growth','Energy','Red Hot Chili Peppers','West','2018','3','38','8854'),
('Growth','Energy','Red Hot Chili Peppers','West','2018','6','106','24698'),
('Growth','Energy','Red Hot Chili Peppers','West','2018','8','131','30523'),
('Growth','Energy','Red Hot Chili Peppers','West','2018','10','81','18873'),
('Growth','Energy','Red Hot Chili Peppers','West','2018','10','115','26795'),
('Growth','Energy','Red Hot Chili Peppers','West','2018','11','172','40076'),
('Growth','Energy','Red Hot Chili Peppers','West','2019','4','14','3262'),
('Growth','Energy','Red Hot Chili Peppers','West','2019','4','79','18407'),
('Growth','Energy','Red Hot Chili Peppers','West','2019','12','38','8854'),
('Growth','Energy','Red Hot Chili Peppers','West','2019','12','54','12582'),
('Growth','Energy','Red Hot Chili Peppers','West','2019','12','66','15378'),
('Growth','Snack','Crocodile Tears','Midwest','2017','2','42','6006'),
('Growth','Snack','Crocodile Tears','Midwest','2017','3','90','12870'),
('Growth','Snack','Crocodile Tears','Midwest','2017','5','94','13442'),
('Growth','Snack','Crocodile Tears','Midwest','2018','1','101','14443'),
('Growth','Snack','Crocodile Tears','Midwest','2018','2','166','23738'),
('Growth','Snack','Crocodile Tears','Midwest','2018','6','30','4290'),
('Growth','Snack','Crocodile Tears','Midwest','2018','7','59','8437'),
('Growth','Snack','Crocodile Tears','Midwest','2018','8','10','1430'),
('Growth','Snack','Crocodile Tears','Midwest','2018','8','163','23309'),
('Growth','Snack','Crocodile Tears','Midwest','2018','10','69','9867'),
('Growth','Snack','Crocodile Tears','Midwest','2019','4','43','6149'),
('Growth','Snack','Crocodile Tears','Midwest','2019','9','5','715'),
('Growth','Snack','Crocodile Tears','Midwest','2019','12','57','8151'),
('Growth','Snack','Crocodile Tears','Northeast','2017','6','23','3289'),
('Growth','Snack','Crocodile Tears','Northeast','2017','10','18','2574'),
('Growth','Snack','Crocodile Tears','Northeast','2018','1','104','14872'),
('Growth','Snack','Crocodile Tears','Northeast','2018','6','47','6721'),
('Growth','Snack','Crocodile Tears','Northeast','2018','9','126','18018'),
('Growth','Snack','Crocodile Tears','Northeast','2019','7','55','7865'),
('Growth','Snack','Crocodile Tears','Northeast','2019','8','68','9724'),
('Growth','Snack','Crocodile Tears','South','2017','4','83','11869'),
('Growth','Snack','Crocodile Tears','South','2017','5','48','6864'),
('Growth','Snack','Crocodile Tears','South','2017','8','5','715'),
('Growth','Snack','Crocodile Tears','South','2017','11','67','9581'),
('Growth','Snack','Crocodile Tears','South','2017','12','73','10439'),
('Growth','Snack','Crocodile Tears','South','2018','1','138','19734'),
('Growth','Snack','Crocodile Tears','South','2018','1','147','21021'),
('Growth','Snack','Crocodile Tears','South','2018','1','154','22022'),
('Growth','Snack','Crocodile Tears','South','2018','2','104','14872'),
('Growth','Snack','Crocodile Tears','South','2018','3','92','13156'),
('Growth','Snack','Crocodile Tears','South','2018','3','125','17875'),
('Growth','Snack','Crocodile Tears','South','2018','4','102','14586'),
('Growth','Snack','Crocodile Tears','South','2018','5','120','17160'),
('Growth','Snack','Crocodile Tears','South','2018','6','160','22880'),
('Growth','Snack','Crocodile Tears','South','2018','7','129','18447'),
('Growth','Snack','Crocodile Tears','South','2018','8','49','7007'),
('Growth','Snack','Crocodile Tears','South','2018','9','144','20592'),
('Growth','Snack','Crocodile Tears','South','2019','1','7','1001'),
('Growth','Snack','Crocodile Tears','South','2019','2','17','2431'),
('Growth','Snack','Crocodile Tears','South','2019','3','34','4862'),
('Growth','Snack','Crocodile Tears','South','2019','3','71','10153'),
('Growth','Snack','Crocodile Tears','South','2019','4','40','5720'),
('Growth','Snack','Crocodile Tears','South','2019','4','88','12584'),
('Growth','Snack','Crocodile Tears','South','2019','5','16','2288'),
('Growth','Snack','Crocodile Tears','South','2019','5','93','11969'),
('Growth','Snack','Crocodile Tears','South','2019','6','7','1001'),
('Growth','Snack','Crocodile Tears','South','2019','6','76','10868'),
('Growth','Snack','Crocodile Tears','South','2019','7','25','3575'),
('Growth','Snack','Crocodile Tears','South','2019','8','48','6864'),
('Growth','Snack','Crocodile Tears','South','2019','12','23','3289'),
('Growth','Snack','Crocodile Tears','South','2019','12','68','9724'),
('Growth','Snack','Crocodile Tears','West','2017','6','66','9438'),
('Growth','Snack','Crocodile Tears','West','2017','9','69','9867'),
('Growth','Snack','Crocodile Tears','West','2017','10','92','13156'),
('Growth','Snack','Crocodile Tears','West','2017','12','64','9152'),
('Growth','Snack','Crocodile Tears','West','2018','1','116','16588'),
('Growth','Snack','Crocodile Tears','West','2018','12','61','8723'),
('Growth','Snack','Crocodile Tears','West','2019','7','12','1716'),
('Growth','Snack','Crocodile Tears','West','2019','12','7','1001'),
('Mature','Health','Panda Gummies','Midwest','2017','3','3','312'),
('Mature','Health','Panda Gummies','Midwest','2017','4','11','1144'),
('Mature','Health','Panda Gummies','Midwest','2017','12','87','9048'),
('Mature','Health','Panda Gummies','Midwest','2018','9','126','13104'),
('Mature','Health','Panda Gummies','Midwest','2018','12','107','11128'),
('Mature','Health','Panda Gummies','Midwest','2019','3','71','7384'),
('Mature','Health','Panda Gummies','Midwest','2019','6','79','8216'),
('Mature','Health','Panda Gummies','Midwest','2019','8','33','3432'),
('Mature','Health','Panda Gummies','Midwest','2019','11','2','208'),
('Mature','Health','Panda Gummies','Northeast','2017','3','11','1144'),
('Mature','Health','Panda Gummies','Northeast','2017','9','15','1560'),
('Mature','Health','Panda Gummies','Northeast','2017','9','91','9464'),
('Mature','Health','Panda Gummies','Northeast','2018','2','55','5720'),
('Mature','Health','Panda Gummies','Northeast','2018','3','33','3432'),
('Mature','Health','Panda Gummies','Northeast','2018','6','91','9464'),
('Mature','Health','Panda Gummies','Northeast','2018','11','101','10504'),
('Mature','Health','Panda Gummies','Northeast','2018','11','125','13000'),
('Mature','Health','Panda Gummies','Northeast','2019','4','1','104'),
('Mature','Health','Panda Gummies','Northeast','2019','12','38','3952'),
('Mature','Health','Panda Gummies','South','2017','1','14','1456'),
('Mature','Health','Panda Gummies','South','2017','2','98','10192'),
('Mature','Health','Panda Gummies','South','2017','3','2','208'),
('Mature','Health','Panda Gummies','South','2017','3','13','1352'),
('Mature','Health','Panda Gummies','South','2017','3','56','5824'),
('Mature','Health','Panda Gummies','South','2017','7','68','7072'),
('Mature','Health','Panda Gummies','South','2017','12','16','1664'),
('Mature','Health','Panda Gummies','South','2017','12','26','2704'),
('Mature','Health','Panda Gummies','South','2018','4','79','8216'),
('Mature','Health','Panda Gummies','South','2018','4','138','14352'),
('Mature','Health','Panda Gummies','South','2018','6','105','10920'),
('Mature','Health','Panda Gummies','South','2018','9','53','5512'),
('Mature','Health','Panda Gummies','South','2018','9','59','6136'),
('Mature','Health','Panda Gummies','South','2018','9','100','10400'),
('Mature','Health','Panda Gummies','South','2018','9','113','11752'),
('Mature','Health','Panda Gummies','South','2018','10','192','19968'),
('Mature','Health','Panda Gummies','South','2018','12','117','12168'),
('Mature','Health','Panda Gummies','South','2018','12','131','13624'),
('Mature','Health','Panda Gummies','South','2019','5','37','3848'),
('Mature','Health','Panda Gummies','South','2019','6','40','4160'),
('Mature','Health','Panda Gummies','South','2019','6','59','6136'),
('Mature','Health','Panda Gummies','South','2019','8','18','1872'),
('Mature','Health','Panda Gummies','South','2019','11','96','8986'),
('Mature','Health','Panda Gummies','West','2017','3','27','2808'),
('Mature','Health','Panda Gummies','West','2017','7','5','520'),
('Mature','Health','Panda Gummies','West','2017','9','19','1976'),
('Mature','Health','Panda Gummies','West','2017','10','30','3120'),
('Mature','Health','Panda Gummies','West','2017','11','84','8736'),
('Mature','Health','Panda Gummies','West','2018','5','125','13000'),
('Mature','Health','Panda Gummies','West','2018','7','40','4160'),
('Mature','Health','Panda Gummies','West','2018','10','94','9776'),
('Mature','Health','Panda Gummies','West','2018','10','101','10504'),
('Mature','Health','Panda Gummies','West','2018','11','157','16328'),
('Mature','Health','Panda Gummies','West','2019','1','75','7800'),
('Mature','Health','Panda Gummies','West','2019','5','95','8892'),
('Mature','Health','Panda Gummies','West','2019','6','19','1976'),
('Mature','Health','Panda Gummies','West','2019','9','20','2080'),
('Mature','Health','Panda Gummies','West','2019','12','96','8986'),
('Mature','Lunchtime','Green Lightning','Midwest','2018','2','33','5313'),
('Mature','Lunchtime','Green Lightning','Midwest','2018','3','114','18354'),
('Mature','Lunchtime','Green Lightning','Midwest','2018','3','119','19159'),
('Mature','Lunchtime','Green Lightning','Midwest','2018','10','155','24955'),
('Mature','Lunchtime','Green Lightning','Midwest','2019','4','91','13186'),
('Mature','Lunchtime','Green Lightning','Midwest','2019','5','64','10304'),
('Mature','Lunchtime','Green Lightning','Midwest','2019','12','52','8372'),
('Mature','Lunchtime','Green Lightning','Midwest','2019','12','66','10626'),
('Mature','Lunchtime','Green Lightning','Northeast','2018','5','105','16905'),
('Mature','Lunchtime','Green Lightning','Northeast','2018','6','30','4830'),
('Mature','Lunchtime','Green Lightning','Northeast','2018','8','90','14490'),
('Mature','Lunchtime','Green Lightning','Northeast','2018','8','126','20286'),
('Mature','Lunchtime','Green Lightning','Northeast','2018','8','131','21091'),
('Mature','Lunchtime','Green Lightning','Northeast','2018','11','134','21574'),
('Mature','Lunchtime','Green Lightning','Northeast','2019','2','45','7245'),
('Mature','Lunchtime','Green Lightning','Northeast','2019','10','9','1449'),
('Mature','Lunchtime','Green Lightning','South','2018','1','58','9338'),
('Mature','Lunchtime','Green Lightning','South','2018','2','105','16905'),
('Mature','Lunchtime','Green Lightning','South','2018','2','169','27209'),
('Mature','Lunchtime','Green Lightning','South','2018','5','41','6601'),
('Mature','Lunchtime','Green Lightning','South','2018','5','47','7567'),
('Mature','Lunchtime','Green Lightning','South','2018','5','85','13685'),
('Mature','Lunchtime','Green Lightning','South','2018','5','145','23345'),
('Mature','Lunchtime','Green Lightning','South','2018','10','123','19803'),
('Mature','Lunchtime','Green Lightning','South','2018','12','91','14651'),
('Mature','Lunchtime','Green Lightning','South','2019','1','29','4669'),
('Mature','Lunchtime','Green Lightning','South','2019','2','68','10948'),
('Mature','Lunchtime','Green Lightning','South','2019','5','47','7567'),
('Mature','Lunchtime','Green Lightning','South','2019','9','36','5796'),
('Mature','Lunchtime','Green Lightning','South','2019','9','87','14007'),
('Mature','Lunchtime','Green Lightning','West','2018','4','109','17549'),
('Mature','Lunchtime','Green Lightning','West','2018','5','72','11592'),
('Mature','Lunchtime','Green Lightning','West','2018','5','111','17871'),
('Mature','Lunchtime','Green Lightning','West','2018','8','32','5152'),
('Mature','Lunchtime','Green Lightning','West','2018','8','123','19803'),
('Mature','Lunchtime','Green Lightning','West','2019','3','62','9982'),
('Mature','Lunchtime','Green Lightning','West','2019','6','78','12558'),
('Mature','Lunchtime','Green Lightning','West','2019','7','81','13041'),
('Mature','Lunchtime','Green Lightning','West','2019','8','67','10787'),
('Mature','Lunchtime','Green Lightning','West','2019','10','67','10787'),
('Mature','Lunchtime','Green Lightning','West','2019','11','97','14055'),
('Mature','Lunchtime','Green Lightning','West','2019','12','40','6440'),
('Mature','Lunchtime','Green Lightning','West','2019','12','56','9016'),
('Mature','Lunchtime','Orange Creepies','Midwest','2019','1','10','3000'),
('Mature','Lunchtime','Orange Creepies','Midwest','2019','4','13','3900'),
('Mature','Lunchtime','Orange Creepies','Midwest','2019','7','71','21300'),
('Mature','Lunchtime','Orange Creepies','Midwest','2019','10','65','19500'),
('Mature','Lunchtime','Orange Creepies','Northeast','2019','6','58','17400'),
('Mature','Lunchtime','Orange Creepies','Northeast','2019','11','86','25800'),
('Mature','Lunchtime','Orange Creepies','South','2019','3','33','9900'),
('Mature','Lunchtime','Orange Creepies','South','2019','3','81','24300'),
('Mature','Lunchtime','Orange Creepies','South','2019','4','3','900'),
('Mature','Lunchtime','Orange Creepies','South','2019','4','28','8400'),
('Mature','Lunchtime','Orange Creepies','South','2019','6','8','2400'),
('Mature','Lunchtime','Orange Creepies','South','2019','6','26','7800'),
('Mature','Lunchtime','Orange Creepies','South','2019','7','62','18600'),
('Mature','Lunchtime','Orange Creepies','South','2019','10','55','16500'),
('Mature','Lunchtime','Orange Creepies','South','2019','12','88','26400'),
('Mature','Lunchtime','Orange Creepies','South','2019','12','100','27000'),
('Mature','Lunchtime','Orange Creepies','West','2019','1','4','1200'),
('Mature','Lunchtime','Orange Creepies','West','2019','1','47','14100'),
('Mature','Lunchtime','Orange Creepies','West','2019','1','59','17700'),
('Mature','Lunchtime','Orange Creepies','West','2019','2','76','22800'),
('Mature','Lunchtime','Orange Creepies','West','2019','5','76','22800'),
('Mature','Lunchtime','Orange Creepies','West','2019','6','67','20100'),
('Mature','Lunchtime','Yellow Zonkers','Midwest','2017','11','64','8576'),
('Mature','Lunchtime','Yellow Zonkers','Midwest','2017','12','91','12194'),
('Mature','Lunchtime','Yellow Zonkers','Midwest','2018','1','159','21306'),
('Mature','Lunchtime','Yellow Zonkers','Midwest','2018','3','136','18224'),
('Mature','Lunchtime','Yellow Zonkers','Midwest','2018','3','175','23450'),
('Mature','Lunchtime','Yellow Zonkers','Midwest','2018','4','120','16080'),
('Mature','Lunchtime','Yellow Zonkers','Midwest','2018','5','52','6968'),
('Mature','Lunchtime','Yellow Zonkers','Midwest','2018','6','86','11524'),
('Mature','Lunchtime','Yellow Zonkers','Midwest','2018','6','95','12730'),
('Mature','Lunchtime','Yellow Zonkers','Midwest','2018','6','143','19162'),
('Mature','Lunchtime','Yellow Zonkers','Midwest','2018','9','62','8308'),
('Mature','Lunchtime','Yellow Zonkers','Midwest','2018','12','137','18358'),
('Mature','Lunchtime','Yellow Zonkers','Midwest','2019','7','61','8174'),
('Mature','Lunchtime','Yellow Zonkers','Midwest','2019','11','29','3886'),
('Mature','Lunchtime','Yellow Zonkers','Midwest','2019','11','33','4422'),
('Mature','Lunchtime','Yellow Zonkers','Northeast','2017','2','7','938'),
('Mature','Lunchtime','Yellow Zonkers','Northeast','2017','2','77','10318'),
('Mature','Lunchtime','Yellow Zonkers','Northeast','2017','9','92','12328'),
('Mature','Lunchtime','Yellow Zonkers','Northeast','2018','5','119','15946'),
('Mature','Lunchtime','Yellow Zonkers','Northeast','2018','6','62','8308'),
('Mature','Lunchtime','Yellow Zonkers','Northeast','2018','8','98','13132'),
('Mature','Lunchtime','Yellow Zonkers','Northeast','2018','11','41','5494'),
('Mature','Lunchtime','Yellow Zonkers','Northeast','2018','12','127','17018'),
('Mature','Lunchtime','Yellow Zonkers','Northeast','2019','3','16','2144'),
('Mature','Lunchtime','Yellow Zonkers','Northeast','2019','5','24','3216'),
('Mature','Lunchtime','Yellow Zonkers','Northeast','2019','5','57','7638'),
('Mature','Lunchtime','Yellow Zonkers','Northeast','2019','7','100','12060'),
('Mature','Lunchtime','Yellow Zonkers','South','2017','4','97','12998'),
('Mature','Lunchtime','Yellow Zonkers','South','2017','5','94','12596'),
('Mature','Lunchtime','Yellow Zonkers','South','2017','6','20','2680'),
('Mature','Lunchtime','Yellow Zonkers','South','2017','6','94','12596'),
('Mature','Lunchtime','Yellow Zonkers','South','2017','8','51','6834'),
('Mature','Lunchtime','Yellow Zonkers','South','2017','10','61','8174'),
('Mature','Lunchtime','Yellow Zonkers','South','2017','11','67','8978'),
('Mature','Lunchtime','Yellow Zonkers','South','2018','4','141','18894'),
('Mature','Lunchtime','Yellow Zonkers','South','2018','11','98','13132'),
('Mature','Lunchtime','Yellow Zonkers','South','2019','5','2','268'),
('Mature','Lunchtime','Yellow Zonkers','South','2019','6','25','3350'),
('Mature','Lunchtime','Yellow Zonkers','South','2019','7','29','3886'),
('Mature','Lunchtime','Yellow Zonkers','South','2019','8','62','8308'),
('Mature','Lunchtime','Yellow Zonkers','South','2019','9','43','5762'),
('Mature','Lunchtime','Yellow Zonkers','South','2019','11','37','4958'),
('Mature','Lunchtime','Yellow Zonkers','West','2017','7','53','7102'),
('Mature','Lunchtime','Yellow Zonkers','West','2017','7','59','7906'),
('Mature','Lunchtime','Yellow Zonkers','West','2017','12','29','3886'),
('Mature','Lunchtime','Yellow Zonkers','West','2018','11','146','19564'),
('Mature','Lunchtime','Yellow Zonkers','West','2018','12','138','18492'),
('Mature','Lunchtime','Yellow Zonkers','West','2018','12','172','23048'),
('Mature','Lunchtime','Yellow Zonkers','West','2019','4','24','3216'),
('Mature','Lunchtime','Yellow Zonkers','West','2019','5','20','2680'),
('Mature','Lunchtime','Yellow Zonkers','West','2019','9','18','2412'),
('Mature','Lunchtime','Yellow Zonkers','West','2019','10','35','4690'),
('Mature','Lunchtime','Yellow Zonkers','West','2019','10','37','4958'),
('Mature','Lunchtime','Yellow Zonkers','West','2019','12','49','6566');


select * from test_table
group by BU,BU_Name,Product,Region,Year,Month,sum;

# Remove SUM and the group by month drops values (doesn't include them in the sum)...
#look at row 6 and 7... run again without sum and the 129 disapears and is not added into the sum

Options: ReplyQuote


Subject
Views
Written By
Posted
386
February 19, 2022 09:05AM
Re: GROUP BY is Broken?
256
February 19, 2022 09:07AM
278
February 19, 2022 09:59AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.