Skip to content

How to get the message count of each channel per month for a specific discord guild?

Query Name

guild_channel_messages_per_month

SQL Query


select 
    distinct guilds_t.id, guilds_t.guild_name, month_timestamp, msg_count 
from (
    select
        distinct DATE_TRUNC('month', msg_timestamp)
                     AS  month_timestamp,
        COUNT(guild_id) AS msg_count,
        guild_id 
    FROM messages_t
        where
            guild_id = '{}'
            and channel_id = '{}'
    GROUP BY guild_id, month_timestamp
) as month_messages_t
join guilds_t on month_messages_t.guild_id = guilds_t.id
order by guilds_t.id, month_timestamp;

Similar Queries