聚合/排序

最后更新:2024-10-08 05:30:08 | 状态:未完成

复杂的查询以及非JDBC协议的数据源要通过

1.Table.aggregation()  service.querys(table)
Table table = new Table("TAB_AGG(DEPT_CODE, TYPE_CODE)");
table.aggregation(Aggregation.COUNT, "*", "QTY");
table.aggregation(Aggregation.COUNT, "DISTINCT SALARY", "DISTINCT_QTY");
table.aggregation(Aggregation.MAX, "SALARY", "SALARY_MAX");
table.aggregation(Aggregation.AVG, "SALARY", "SALARY_AVG");
table.group("TYPE_CODE", "DEPT_CODE");
table.having("count(*) > 1");
DataSet set = service.querys(table, "ID>10");

2.RunPrepare.aggregation()  service.querys(prepare)

RunPrepare prepare = TableBuilder.init("TAB_AGG").build();
prepare.aggregation(Aggregation.COUNT, "*", "QTY");
prepare.aggregation(Aggregation.COUNT, "DISTINCT SALARY", "DISTINCT_QTY");
prepare.aggregation(Aggregation.MAX, "SALARY", "SALARY_MAX");
prepare.aggregation(Aggregation.AVG, "SALARY", "SALARY_AVG");
prepare.group("TYPE_CODE", "DEPT_CODE");
prepare.having("count(*) > 1");
DataSet set = service.querys(prepare, "ID>10");

3.service.aggregation().querys();

service.aggregation()
.table("TAB_AGG")
.aggregation(Aggregation.COUNT, "*", "QTY")
.aggregation(Aggregation.COUNT, "DISTINCT SALARY", "DISTINCT_QTY")
.aggregation(Aggregation.MAX, "SALARY", "SALARY_MAX")
.aggregation(Aggregation.AVG, "SALARY", "SALARY_AVG")
.group("TYPE_CODE", "DEPT_CODE")
.order("TYPE_CODE")
.having("count(*) > 1")
.querys();
生成SQL:
SELECT 
	COUNT(*) QTY, COUNT(DISTINCT SALARY) DISTINCT_QTY, MAX(SALARY) SALARY_MAX, AVG(SALARY) SALARY_AVG
FROM TAB_AGG
	GROUP BY TYPE_CODE, DEPT_CODE
HAVING count(*) > 1
ORDER BY TYPE_CODE ASC 
首页 最近更新 搜索 提交 回复