| 123456789101112131415161718192021222324252627 |
- using Invercargill.Expressions;
- using InvercargillSql.Orm;
- using InvercargillSql.Orm.Projections;
- /**
- * Aggregate projection demonstrating GROUP BY and aggregate functions.
- */
- public class SalesReport : Object {
- public string category { get; set; }
- public int64 total_orders { get; set; }
- public double total_revenue { get; set; }
- public double avg_order_value { get; set; }
-
- public SalesReport() {
- category = "";
- }
-
- public static void configure_projection(ProjectionBuilder<SalesReport> p) throws ProjectionError {
- p.source<Order>("o")
- .join<Product>("p", expr("o.product_id == p.id"))
- .group_by(expr("p.category"))
- .select<string>("category", expr("p.category"), (x, v) => x.category = v)
- .select<int64?>("total_orders", expr("COUNT(o.id)"), (x, v) => x.total_orders = v)
- .select<double?>("total_revenue", expr("SUM(o.total)"), (x, v) => x.total_revenue = v)
- .select<double?>("avg_order_value", expr("AVG(o.total)"), (x, v) => x.avg_order_value = v);
- }
- }
|