我正在尝试将此Oracle查询转换为HSQL,但我遇到了困难。
select a.t_user_id, listagg(et.event_type_name,', ') within group (order by a.t_user_id )
from t_agency a inner join t_agency_event_type aet on a.t_user_id = aet.agency_id
inner join t_event_type et on aet.t_event_type_id=et.id
group by a.t_user_id;
任何人都可以帮助我吗?提前谢谢!
增加:
我的HSQL查询是这样的:
Query queryEventTypes = em.createQuery("select agency, GROUP_CONCAT(et.eventTypeName SEPARATOR ', ') as eventTypeName " +
"from TAgency agency join agency.tAgencyEventTypes eat " +
"join eat.tEventType et " +
"group by hiredAgency.tUserId, hiredAgency.address, hiredAgency.city, hiredAgency.information, "
+ "hiredAgency.website");
但它给了我错误:
unexpected token: SEPARATOR near line 1, column 46 [select agency, GROUP_CONCAT(et.eventTypeName SEPARATOR ', ')
as eventTypeName from bg.fmi.master.thesis.model.TAgency agency join agency.tAgencyEventTypes eat join eat.tEventType et
group by hiredAgency.tUserId, hiredAgency.address, hiredAgency.city, hiredAgency.information, hiredAgency.website]
答案 0 :(得分:0)
尝试HSQLDB版本2.3.x及更高版本支持的GROUP_CONCAT功能。 HSQLDB语法不同并在此处记录。
http://hsqldb.org/doc/2.0/guide/dataaccess-chapt.html#dac_aggregate_funcs
指南中给出的示例显示了如何指定结果的分组和排序;
SELECT LASTNAME, GROUP_CONCAT(DISTINCT FIRSTNAME ORDER BY FIRSTNAME DESC SEPARATOR ' * ') FROM Customer GROUP BY LASTNAME