1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-02 22:58:01 +00:00

Add Count Records By Type as a postgres til.

This commit is contained in:
jbranchaud
2015-06-10 08:28:17 -05:00
parent 104d5ef082
commit 74a275079e
2 changed files with 18 additions and 0 deletions

View File

@@ -52,6 +52,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
### postgres
- [Count Records By Type](postgres/count-records-by-type.md)
- [Extracting Nested JSON Data](postgres/extracting-nested-json-data.md)
- [Timestamp Functions](postgres/timestamp-functions.md)
- [Toggling The Pager In PSQL](postgres/toggling-the-pager-in-psql.md)

View 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
```