openlang

Counting how often each distinct entry appears in a database field

I have a Postgre database containing around 12 columns. Its fourth column is named column4. The database contains 120 rows and column4 can hold c4entry1, c4entry2, c4entry3...c4entry23, c4entry24. I'd like a printed table giving the frequency of every distinct value.

The resulting table would be something like:

Value(of column4)         frequency of that value
     c4entry1                        2
     c4entry2                        6
     c4entry3                        4
     c4entry4                        8
     c4entry5                        2
     c4entry6                        3
        .                            .
        .                            .
        .                            .

Which command would produce that output?

The conversation continues 2

Follow the reasoning
  1. Permalink

    Apply grouping to your chosen column, the one of interest here, then count the rows belonging to each resulting group:

    SELECT column4, COUNT(*) FROM entries
    GROUP BY column4

Other sides of the same question

  1. Missing field through a derived table in SQL

    I'm executing the following SQL statement: It produces the following error: #1054 - Unknown column 'shipping.post_id' in 'on…

    Replies 2Latest activity sql
  2. Testing D arrays for a matching entry

    with associative arrays this is possible how is this done with ordinary arrays? I'd like a validation expression, for example

    Replies 2Latest activity d
  3. Removing an optional column safely with PostgreSQL 9+

    I want to remove a column belonging to a table. What's the way to determine whether that column is present? I read the manual…

    Replies 2Latest activity sql