我正在尝试使用 JOOQ 以编程方式在 Java 中构建以下查询:
select emisor,
anio,
mes,
sum(case when codigo = '01' then total else 0 end) as facturas,
sum(case when codigo = '03' then total else 0 end) as boletas,
sum(case when codigo = '07' then total else 0 end) as notas_credito,
sum(case when codigo = '08' then total else 0 end) as notas_debito,
sum(case when codigo = 'RC' then total else 0 end) as resumenes,
sum(case when codigo = 'RA' then total else 0 end) as anulaciones,
sum(case when codigo = '40' then total else 0 end) as percepciones,
sum(case when codigo = '20' then total else 0 end) as retenciones,
sum(case when codigo = 'RV' then total else 0 end) as reversiones,
sum(case when codigo = '09' then total else 0 end) as guias
from (select ruc_emisor as emisor,
year(fec_registro) as anio,
month(fec_registro) as mes,
substring(nom_solicitud, 13, 2) as codigo,
count(*) as total
from bd_ose.tx_solicitud
where year(fec_registro) = '2019'
and month(fec_registro) = 7
group by ruc_emisor, anio, mes, codigo
UNION
select num_ruc as emisor,
year(fec_registro) as anio,
month(fec_registro) as mes,
cod_cpe as codigo,
count(*) as total
from bd_ose.tx_comprobante_inf
where year(fec_registro) = '2019'
and month(fec_registro) = 7
group by num_ruc, anio, mes, codigo
) solicitudes
group by emisor, anio, mes
order by emisor;
在 SQL 和 JOOQ 方面,我仍然相当缺乏经验,但我决定从内部开始,逐步解决问题。当我尝试将 .union() 方法应用于两个内部子查询时,我遇到了问题。我的 IDE 突出显示了一个类型不匹配错误,指出 union 需要一个类型为“org.jooq.Select<...”的参数,而我提供的参数类型为“org.jooq.SelectHavingStep<... " - 这是从 .groupBy() 返回的类型
我已经检查了 [union docs] ( https://www.jooq.org/doc/3.11/manual/sql-building/sql-statements/select-statement/union-clause/ )的文档并尝试寻找类似的其他地方的案例,但不幸的是还没有成功。
万千封印
相关分类