peewee Documentation Release 3.6.0per-product sales totals in only the top sales regions. Our model looks like this: class Order(Model): region = TextField() amount = FloatField() product = TextField() quantity = IntegerField() Here th.html]. WITH regional_sales AS ( SELECT region, SUM(amount) AS total_sales FROM orders GROUP BY region ), top_regions AS ( SELECT region FROM regional_sales WHERE total_sales > (SELECT regional_sales) ) SELECT region, product, SUM(quantity) AS product_units, SUM(amount) AS product_sales FROM orders WHERE region IN (SELECT region FROM top_regions) GROUP BY region, product; With0 码力 | 377 页 | 399.12 KB | 1 年前3
peewee Documentation
Release 3.6.0per-product sales totals in only the top sales regions. Our model looks like this: class Order(Model): region = TextField() amount = FloatField() product = TextField() quantity = IntegerField() Here is how postgresql documentation. WITH regional_sales AS ( SELECT region, SUM(amount) AS total_sales FROM orders GROUP BY region ), top_regions AS ( SELECT region FROM regional_sales WHERE total_sales > (SELECT SUM(total_sales) regional_sales) ) SELECT region, product, SUM(quantity) AS product_units, SUM(amount) AS product_sales FROM orders WHERE region IN (SELECT region FROM top_regions) GROUP BY region, product; With Peewee0 码力 | 302 页 | 1.02 MB | 1 年前3
共 2 条
- 1













