SQL小提琴
MySQL 5.5.32 架构设置:
CREATE TABLE aggregate_season_product
(`season` varchar(2), `collection` varchar(2), `forecast_name` varchar(2), `product_key` int, `aggregated_sale` int)
;
INSERT INTO aggregate_season_product
(`season`, `collection`, `forecast_name`, `product_key`, `aggregated_sale`)
VALUES
('ss', 'cc', 'f1', 1, 11),
('ss', 'cc', 'f1', 3, 10),
('ss', 'cc', 'f1', 2, 5),
('ss', 'cc', 'f2', 5, 11),
('ss', 'cc', 'f2', 4, 7)
;
查询 1:
select *
from aggregate_season_product
where season = 'ss' and collection = 'cc'
ORDER by
season,
collection,
forecast_name,
aggregated_sale
结果:
| SEASON | COLLECTION | FORECAST_NAME | PRODUCT_KEY | AGGREGATED_SALE |
|--------|------------|---------------|-------------|-----------------|
| ss | cc | f1 | 2 | 5 |
| ss | cc | f1 | 3 | 10 |
| ss | cc | f1 | 1 | 11 |
| ss | cc | f2 | 4 | 7 |
| ss | cc | f2 | 5 | 11 |