for a comment table

There are the following requirements:

Query how many comments each user has posted since a certain time

You can use the following SQL to query:

 select
    user_id,
    count(*)
from
    comment
where
    created_at > '2022-06-20'
group by
    user_id;

There is a new requirement:

How many users have commented since the query

 select
    count(*)
from
    (
        select
            user_id
        from
            comment
        where
            created_at > '2022-06-20'
        group by
            user_id
    ) as user_id_group_by

universe_king
3.4k 声望680 粉丝