vapor / fluent

Vapor ORM (queries, models, and relations) for NoSQL and SQL databases
https://docs.vapor.codes/4.0/fluent/overview/
MIT License
1.32k stars 172 forks source link

how to get the repeat times of a column #718

Closed DamonHu closed 3 years ago

DamonHu commented 3 years ago
field1 field2 field3
aaa xxxx 1
aaa1 xxxx 2
aaa2 xxxx 2
aaa3 xxxx 1
aaa4 xxxx 1

As in the example above. I want to get the sum number of 'field3' as 1 and 2 and its corresponding object array of 'field1'. I searched the usage of MySQL, which is roughly like this. If I use 'Vapor', how can I achieve it?

select field3,count(*) as count from user group by field3 having count>1;

I've been puzzled about this problem for many days. I hope I can get your advice. Thank you very much

0xTim commented 3 years ago

This is not something that Fluent currently supports so you'll need to use a raw query to do this. See the docs here on how to do that