4

I'm trying to migrate one of my Postgres tables at ClickHouse. Here what I came up with at ClickHouse:

CREATE TABLE loads(
    country_id UInt16,
    partner_id UInt32,
    is_unique UInt8,
    ip String,
    created_at DateTime
) ENGINE=MergeTree PARTITION BY toYYYYMM(created_at) ORDER BY (created_at);

is_unique here is a Boolean with 0 or 1. I wanna know count for aggregates: country_id, partner_id and created_at, but also I wanna know how much from these loads are unique loads. At Postgres it looks like:

SELECT
    count(*) AS loads,
    count(*) FILTER (WHERE is_unique) AS uniq,
    country_id,
    partner_id,
    created_at::date AS ts
FROM loads
GROUP BY ts, country_id, partner_id

Is it possible at ClickHouse or should I think again about how to aggregate the data? I didn't find any clues at manual except count can get expr instead of asterisk, but count(is_unique = 1) doesn't work and just returns the same amount as count(*).

1 Answer 1

12

I just found an answer in minutes after posting:

SELECT count(*), countIf(is_unique = 1) /* .. */

Good luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.