mirror of
https://github.com/jbranchaud/til
synced 2026-01-13 03:58:01 +00:00
Add Count Records By Type as a postgres til.
This commit is contained in:
17
postgres/count-records-by-type.md
Normal file
17
postgres/count-records-by-type.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# Count Records By Type
|
||||
|
||||
If you have a table with some sort of type column on it, you can come up
|
||||
with a count of the records in that table by type. You just need to take
|
||||
advantage of `group by`:
|
||||
|
||||
```sql
|
||||
> select type, count(*) from pokemon group by type;
|
||||
|
||||
type | count
|
||||
-----------------
|
||||
fire | 10
|
||||
water | 4
|
||||
plant | 7
|
||||
psychic | 3
|
||||
rock | 12
|
||||
```
|
||||
Reference in New Issue
Block a user