Ich habe eine einfache PostgreSQL-Abfrage Ich habe Probleme bei der Übersetzung in Slick-Abfrage. Ich bleibe in Syntax-Suppe stecken, wenn groupBy
Klausel verwendet wird.Problemlose Konvertierung von einfachen PostgreSQL-Abfrage zu Slick-Abfrage
SELECT u.id AS investor_id,
u.account_type,
i.first_name,
issuer_user.display_name AS issuer_name,
p.legal_name AS product_name,
v.investment_date,
iaa.as_of AS CCO_approval_date,
v.starting_investment_amount,
v.maturity_date,
v.product_interest_rate,
v.product_term_length,
i.user_information_id,
v.id AS investment_id
FROM investors u
JOIN
(SELECT ipi.investor_id,
ipi.first_name,
ipi.user_information_id
FROM investor_personal_information ipi
JOIN
(SELECT investor_id,
MAX(id) AS Max_Id
FROM investor_personal_information
GROUP BY investor_id) M ON ipi.investor_id = m.investor_id
AND ipi.id = m.Max_Id) i ON u.id = i.investor_id
JOIN investments v ON u.id = v.investor_id
JOIN sub_products AS sp ON v.sub_product_id = sp.id
JOIN products AS p ON p.id = sp.product_id
JOIN company AS c ON c.id = p.company_id
JOIN issuers AS issuer ON issuer.id = c.issuer_id
JOIN users AS issuer_user ON issuer.owner = issuer_user.id
JOIN investment_admin_approvals AS iaa ON iaa.investment_id = v.id
ORDER BY i.first_name DESC;
ich mit dem Schreiben angefangen habe es
val query = {
val investorInfoQuery = (for {
i <- InvestorPersonalInformation
} yield (i)).groupBy {
_.investorId
}.map {
case (id, rest) => {
id -> rest.map(_.id).max
}
}
}
Ich weiß, ich habe Bankabfragen in eine große Abfrage erstellen und anwenden auf sie separat verbindet. Kann mir jemand helfen, mich zu führen oder mir ein paar Beispiele zu geben? Slick ist hart.
Eine Option ist Plain SQL in Slick. Sie können Ihre vorhandene SQL verwenden und sie mit slick einem Ergebnistyp zuordnen. –