I'm trying to convert the following SQL query into corresponding Rust Diesel code:
SELECT COUNT(*)
FROM BookStore
WHERE BookName IN ('Lord of the Rings', 'Hobbit')
GROUP BY StoreId
HAVING COUNT(DISTINCT BookName) = 2
I was able to translate it thus far into:
let bookNames = vec!["Lord of the Rings", "Hobbit"];
let subquery = bookStores::table
.select(count_star())
.filter(bookName.eq_any(bookNames));
which I believe translates to:
SELECT COUNT(*)
FROM BookStore
WHERE BookName IN ('Lord of the Rings', 'Hobbit')
I'm having trouble finding any Diesel equivalent for the GROUP BY
and the HAVING
SQL clauses. Do these clauses even exist in Diesel?