我想生产这种SQL用油滑1.0.0:如何写嵌套查询在SELECT子句
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;
我最成功的尝试是(我放弃了“加入”的一部分,所以它更具有可读性):
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))
产生的子查询缺少括号中的SQL:
select
x2.categoryId,
x2.title,
select count(x3.productId) from products x3
from
categories x2
where x2.parentCategoryId = 2
这显然是无效的SQL 任何想法如何让SLICK把这些括号放在正确的地方?或者也许有不同的方式来实现这一目标?
你可以发布你一起尝试? – 2013-02-17 10:33:47
我发布了迄今为止我得到的结果 – wassertim 2013-02-17 13:28:13
这看起来像查询编译器中的一个bug /监督。也许你应该提交一份错误报告。 – 2013-02-17 22:37:07