Distinct with count

I used this query and it works select distinct type from db; but now I want to know how many of each type there are, so I’m using

cbq> select distinct type, count(type) from db;
{
    "requestID": "38815a08-8dd1-43e5-ba3f-6784b26f496d",
    "signature": {
        "$1": "number",
        "type": "json"
    },
    "results": [
        {
            "$1": 10349,
            "type": "geofence_event"
        }
    ],
    "status": "success",
    "metrics": {
        "elapsedTime": "295.75444ms",
        "executionTime": "295.563688ms",
        "resultCount": 1,
        "resultSize": 73
    }
}

How do I make it include all the types with their count?

Add a group by to your query.

select distinct type, count(type) from db group by type;

select type, count(*) from db group by type;

1 Like