I want to know stories times a subscriber_id
liked a hashtag that are about ads that we call eclipse_id
.
I have two tables in my database:
Swipe that gives me if a subscriber liked an advertisement:
A subscriber liked an advertisement when state
= {2,3,5,6,8,9}
Here is the eclipse_hastag database with the correspondence between the advertisements and the hashtag with which they are associated.
Here is the query to know if a subscriber_id
liked a hashtag through an advertisement:
-- matrice utilisateur, hastag
SELECT COUNT (swipe.state),eclipse_hashtag.hashtag_id,swipe.subscriber_id FROM swipe
INNER JOIN eclipse_hashtag ON eclipse_hashtag.eclipse_id = swipe.eclipse_id
WHERE swipe.state= 3 OR swipe.state = 6 or swipe.state=9
GROUP BY eclipse_hashtag.hashtag_id,swipe.subscriber_id
ORDER BY eclipse_hashtag.hashtag_id DESC;
I think the solution was a double JOIN peron I'm not sure and I do not know how to do them and the next one is my first:
-- matriz usario, hashtag
SELECT COUNT(swipe.eclipse_id), subscriber_hashtag.hashtag_id,subscriber_hashtag.subscriber_id FROM subscriber_hashtag
-- join para que las publicidades/eclipses que gusta un usarios estan vinculadas con las de la tabla de correspondencia con los hashtag
INNER JOIN eclipse_hashtag ON eclipse_hashtag.hashtag_id = subscriber_hashtag.hashtag_id
-- join para que los usarios estan vinculadas con los de la tabla de correspondencia con los hashtag
LEFT OUTER JOIN swipe ON subscriber_hashtag.subscriber_id = swipe.subscriber_id
-- recobremos los "me gusta"
WHERE swipe.state= 3 OR swipe.state = 6 or swipe.state=9
GROUP BY subscriber_hashtag.hashtag_id,subscriber_hashtag.subscriber_id
ORDER BY subscriber_hashtag.hashtag_id DESC;
Here is the output, but it seems a bit high and I do not know why the subscriber_id
is not ordered.