我试图将以下查询转换为QueryDSL,我不知道如何从子查询结果集中获取实际结果。我只想按子查询结果集进行分组,并从中填充实际结果集。
select ha.host_model, ha.MACHINE_TYPE, ha.END_OF_LIFE_DT,
ha.END_OF_SERVICE_LIFE_DT,
ha.END_OF_SALE_DT,
ha.END_OF_ENGINEERING_DT,
ha.SOFT_MAINTENANCE_END_DT,
ha.CONTRACT_RENEWAL_END_DT from (
SELECT distinct h.host_id,
h.host_model,
h.MACHINE_TYPE,
m.manufacturer_name,
o.host_platform,
e.END_OF_LIFE_DT,
e.END_OF_SERVICE_LIFE_DT,
e.END_OF_SALE_DT,
e.END_OF_ENGINEERING_DT,
e.SOFT_MAINTENANCE_END_DT,
e.CONTRACT_RENEWAL_END_DT
FROM tf_host h
JOIN tf_eol e
ON h.eol_id = e.eol_id
JOIN tf_manufacturer m
ON h.manufacturer_id = m.manufacturer_id
JOIN tf_os o
ON h.os_id = o.os_id
WHERE HOST_SERVERFLAG = 0) ha group by ha.host_model, ha.MACHINE_TYPE, ha.END_OF_LIFE_DT,
ha.END_OF_SERVICE_LIFE_DT,
ha.END_OF_SALE_DT,
ha.END_OF_ENGINEERING_DT,
ha.SOFT_MAINTENANCE_END_DT,
ha.CONTRACT_RENEWAL_END_DT
order by ha.host_model;
答案 0 :(得分:1)
使用PathBuilder
并使用get
方法从子查询中选择元素。将路径声明为PathBuilder<Tuple> ha = new PathBuilder<>(Tuple.class, "ha")
。可以将此视为为子查询创建别名ha
。接下来,通过在子查询对象上使用.as(ha)
将子查询别名为路径。最后使用ha.get(tableName.columnName)
引用列。