A new way to solve complex SQL

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

A new way to solve complex SQL

yonghe wang
github: https://github.com/braisdom/ObjectiveSql

Java codes:

Order.Table orderTable = Order.asTable();
Select select = new Select();

select.project(sum(orderTable.amount) / sum(orderTable.quantity) * 100)
        .from(orderTable)
        .where(orderTable.quantity > 30 &&
            orderTable.salesAt.between("2020-10-10 00:00:00", "2020-10-30
23:59:59"))
        .groupBy(orderTable.productId);

SQL generated:

SELECT ((((SUM(`T0`.`amount` ) / SUM(`T0`.`quantity` ) )) * 100))
FROM `orders` AS `T0`
WHERE ((`T0`.`quantity` > 30) AND
       `T0`.`sales_at` BETWEEN '2020-10-10 00:00:00' AND '2020-10-30
23:59:59')
GROUP BY `T0`.`product_id`

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/7f02a8e4-d885-49c2-9c61-1caf7d0781c3n%40googlegroups.com.