Created
December 2, 2019 06:12
-
-
Save ytnobody/abac5a34fa533e9185208e82c0dfb039 to your computer and use it in GitHub Desktop.
[Ecto] SELECT bookshelf.id AS bookshelf_id, COUNT(book.id) AS books_count FROM bookshelf JOIN book ON bookshelf.id = book.bookshelf_id GROUP BY bookshelf.id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from(bookshelf in Bookshelf, | |
join: book in Book, on bookshelf.id == book.bookshelf_id, | |
group_by: bookshelf.id, | |
select: %{bookshelf_id: bookshelf.id, books_count: count(book.id)} | |
) |> Repo.all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment