Sto cercando di produrre questo SQL con SLICK 1.0.0:Come scrivere query nidificate nel selezionare clausola
select
cat.categoryId,
cat.title,
(
select
count(product.productId)
from
products product
right join products_categories productCategory on productCategory.productId = product.productId
right join categories c on c.categoryId = productCategory.categoryId
where
c.leftValue >= cat.leftValue and
c.rightValue <= cat.rightValue
) as productCount
from
categories cat
where
cat.parentCategoryId = 2;
Il mio tentativo di maggior successo è (ho lasciato cadere il "si unisce" parte, in modo che sia più leggibile):
def subQuery(c: CategoriesTable.type) = (for {
p <- ProductsTable
} yield(p.id.count))
for {
c <- CategoriesTable
if (c.parentId === 2)
} yield(c.id, c.title, (subQuery(c).asColumn))
che produce l'SQL manca parentesi nella subquery:
select
x2.categoryId,
x2.title,
select count(x3.productId) from products x3
from
categories x2
where x2.parentCategoryId = 2
che è ovviamente SQL valida 0.123.Qualche idea su come avere SLICK metti queste parentesi nel posto giusto? O forse c'è un modo diverso per raggiungere questo obiettivo?
potete inserire al fianco dei tuoi tentativi? –
Ho postato quello che ho ottenuto finora – wassertim
Questo mi sembra un bug/svista nel compilatore di query per me. Forse dovresti presentare un bug report. –