Converting from SQL raw query to GORM

Viewed 21

I wrote a SQL query to design an ORM. Now, I am trying to convert this query to GORM. I read the documentation but I didn't make a proper decision if I use Clouse or conditions.

This is the SQL query I am intending to convert

select collection, count(*) as item_count from collections group by collection order by item_count desc, collection

Thanks in advance.

1 Answers

Something like

db.Select("collection", "count(*) as item_count").Group("collection").Order("item_count desc, collection").Find(&results)

should do the trick. Is that what you are looking for? If not, please comment and clarify.

Related