有表如下;
获取某年份、某地区、某产品的销售总额,
或者根据需要把字段顺序换一下;
sql">insert into sales (product, year, region, amount) values ('飞机','2000','东部',5);
insert into sales (product, year, region, amount) values ('飞机','2001','中部',11);
insert into sales (product, year, region, amount) values ('飞船','2000','西部',6);
insert into sales (product, year, region, amount) values ('飞艇','2000','东部',7);
insert into sales (product, year, region, amount) values ('飞机','2000','北部',5);
insert into sales (product, year, region, amount) values ('飞机','2001','南部',13);
insert into sales (product, year, region, amount) values ('飞船','2001','东部',9);
insert into sales (product, year, region, amount) values ('飞船','2000','北部',17);
insert into sales (product, year, region, amount) values ('飞艇','2000','东部',21);
insert into sales (product, year, region, amount) values ('飞船','2000','东部',23);
insert into sales (product, year, region, amount) values ('飞机','2000','东部',23);
insert into sales (product, year, region, amount) values ('飞船','2001','东部',23);select * from sales;SELECT year, region, product, SUM(amount) AS 销售总额
FROM sales
GROUP BY year, region, product;SELECT product,year, region, SUM(amount) AS 销售总额
FROM sales
GROUP BY product,year, region;