提问人:user1842633 提问时间:10/22/2020 最后编辑:rsalmeiuser1842633 更新时间:5/10/2022 访问量:1751
如何在 Diesel 中编写 GROUP BY 或 HAVING 子句?
How do I write a GROUP BY or HAVING clause in Diesel?
问:
我正在尝试将以下 SQL 查询转换为相应的 Rust Diesel 代码:
SELECT COUNT(*)
FROM BookStore
WHERE BookName IN ('Lord of the Rings', 'Hobbit')
GROUP BY StoreId
HAVING COUNT(DISTINCT BookName) = 2
到目前为止,我能够将其翻译成:
let bookNames = vec!["Lord of the Rings", "Hobbit"];
let subquery = bookStores::table
.select(count_star())
.filter(bookName.eq_any(bookNames));
我相信可以翻译为:
SELECT COUNT(*)
FROM BookStore
WHERE BookName IN ('Lord of the Rings', 'Hobbit')
我无法找到 和 SQL 子句的任何 Diesel 等效项。这些条款甚至在柴油中存在吗?GROUP BY
HAVING
答: 暂无答案
评论
count_star()