【发布时间】:2014-11-16 11:55:53
【问题描述】:
我有这个问题:
Field<String> yearMonth = DSL.field("FORMATDATETIME({0}, 'yyyy-MM')",
String.class, LICENZE.CREATION_DATE).as("anno_mese");
List<Record3<Integer, String, String>> records =
create.select(DSL.count().as("num_licenze"), LICENZE.EDIZIONE, yearMonth).
from(LICENZE).
groupBy(LICENZE.EDIZIONE, yearMonth).
orderBy(yearMonth).
fetch();
此查询生成:
select
count(*) "num_licenze",
"PUBLIC"."LICENZE"."EDIZIONE",
FORMATDATETIME("PUBLIC"."LICENZE"."CREATION_DATE", 'yyyy-MM') "anno_mese"
from "PUBLIC"."LICENZE"
group by
"PUBLIC"."LICENZE"."EDIZIONE",
"anno_mese"
order by "anno_mese" asc
执行它我得到:Column "anno_mese" not found; SQL statement
测试生成的查询并在查询的每个部分中删除 anno_mese 中的引号,以使查询正常工作。
是我的查询错误还是我以错误的方式使用了 jooq?
这个查询中的别名并不那么重要,我也可以不使用它来运行查询,只是为了了解它是如何工作的。 我使用 h2 作为数据库。
感谢您的帮助
【问题讨论】: