我有一个包含5个连接的postgres查询,执行该查询需要10秒钟以上的时间。我用横向联接概念重新编写了查询,现在它在不到1秒的时间内执行。我想用TypeORM编写该查询,但找不到任何方法。任何帮助表示赞赏。
这是需要转换为TypeORM的查询
FROM "institution" "i"
INNER JOIN "financial_account" "fa" ON "fa"."institutionId"="i"."id"
left join (
select h1.*
from holding as h1
inner join (
select cast(max(h3.holding_date) as DATE) holding_date,h3."accountId"
From "holding" as h3
group by h3."accountId"
) as h2 on h2."accountId" = h1."accountId" and h2."holding_date" = cast(h1."holding_date" as date)
) "h" on "h"."accountId" = "fa".id
LEFT JOIN "securities" "sec" ON "sec"."id"="h"."securityId"
LEFT JOIN "symbol" "sym" ON "sym"."id"="sec"."symbolId" AND "sym"."trRIC"="sec"."symbolTrRIC"
where "i".af_user_id='1234'
ORDER BY "h".institution_value desc;