From 74a275079e45ff505d30b94b7c6175fc1955887a Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Wed, 10 Jun 2015 08:28:17 -0500 Subject: [PATCH] Add Count Records By Type as a postgres til. --- README.md | 1 + postgres/count-records-by-type.md | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 postgres/count-records-by-type.md diff --git a/README.md b/README.md index 5ac2647..65abd35 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/postgres/count-records-by-type.md b/postgres/count-records-by-type.md new file mode 100644 index 0000000..829b136 --- /dev/null +++ b/postgres/count-records-by-type.md @@ -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 +```