Count relations
Sometimes you may want to return a count of relations (for example, a user’s post count). To accomplish this, you can do as the example below.
Having the query below in the file select-users-with-post-count.sql
:
TypeSQL will gererate the function selectUsersWithPostCount
:
Result:
(index) | name | postCount |
---|---|---|
0 | user2 | 3 |
1 | user1 | 2 |
2 | user3 | 1 |
3 | user4 | 0 |