# איך לספור לייקים שהתקבלו, למעט קבוצה ספציפית?

**URL:** <https://meta.discourse.org/t/how-to-count-likes-received-excluding-a-specific-group/224304>\
**Category:** Data & reporting\
**Tags:** sql-query\
**Created:** [14 באפריל,‏ 2022,‏ 4:58pm UTC](https://meta.discourse.org/t/how-to-count-likes-received-excluding-a-specific-group/224304 "2022-04-14T16:58:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ítalo\_Dias](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/%C3%ADtalo_dias/32/256934_2.png) [@Ítalo\_Dias](https://meta.discourse.org/u/%C3%8Dtalo_Dias)\
**Post date:** [14 באפריל,‏ 2022,‏ 4:58pm UTC](https://meta.discourse.org/t/how-to-count-likes-received-excluding-a-specific-group/224304/1 "2022-04-14T16:58:59Z")

</div>

Hey, folks! How are you doing?

I’m kinda new to building queries in SQL for my community, so I’m stuck on one issue.

I have to build a query where I get data related to the threads created by a specific group in the community. This is what I got so far:

```plaintext
-- [params]
-- int :months_ago = 1

WITH query_period as (
    SELECT
        date_trunc('month', CURRENT_DATE) - INTERVAL ':months_ago months' as period_start,
        date_trunc('month', CURRENT_DATE) - INTERVAL ':months_ago months' + INTERVAL '1 month' - INTERVAL '1 second' as period_end
)

SELECT
    t.id as topic_id, 
    t.title,
    u.username,
    t.views,
    t.posts_count
    
FROM topics t

RIGHT JOIN query_period qp
    ON t.created_at >= qp.period_start
        AND t.created_at <= qp.period_end

INNER JOIN users as u 
    ON t.user_id = u.id
    
WHERE t.user_id > 0

and u.username in ('maria.narvaez', 'Joao.Caique', 'camila.ochoa', 
'Caroline.Freitas','dante.chacon', 'maria.novaes', 'FernandaVivacqua',
'gabriea.marta', 'IgorMello', 'Jay', 'joaostoky', 'Julio.Torquato', 
'Luis_Quesada', 'maiara.zotelli', 'natalia.bispo', 'rbussola',
'talissa','tfgouveia', 'Victor.Ferreira')

```

I got almost everything I needed. The only data remaining is the quantity of likes\_received in these threads. But, I gotta count all likes, excluding the likes from one specific group.

How can I do it? I googled some solutions and I found things regarding CTEs, however I don’t know how to use them properly.

I would appreciate any help or hint,  
thanks in advance.
