tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.68k stars 390 forks source link

How to write this in tortoise #1405

Open hu0514 opened 1 year ago

hu0514 commented 1 year ago

select count() from (select count() as count_1 from group GROUP BY user_id) tmp where count_1 > 300

How to write this in tortoise

waketzheng commented 1 year ago
await Group.annotate(count_1=Count('user_id')).group_by('user_id').filter(count_1__gt=300).values('user_id', 'count_1')
# [{'user_id': 1, 'count_1': 301}, ...]