@bglusman I think @kip is right on this one. If you are not doing aggregates (like counting the number of stocked items for a particular type) group by is not needed.
It is hard to say what is wrong without seeing the error messages you get from your query.
A few things to help your troubleshooting:
- Does the raw SQL work in psql?
- If it works, try it with and without the group by clause and then you can confirm they do the same thing
- Does the ecto query work without the group by clause?
- Strip down the query until it works and then add in more elements to get to where you want to be. For example start with just joining one table, make sure the result make sense and then continue with the next one.
What I can see in the link provided it cannot work as your group by clause only contains column whereas your select contains many. Any non-aggregated field in the select clause must be part of the group by clause.
As a side-note. Other’s say this is complicated SQL but this is as straight-forward as it gets. A simple select with a few joins and a where clause.


















