Get number of rows in reference
I have two tables with one referencing the other one. Here is the code:
CREATE TABLE blogs (
article LONGTEXT,
id VARCHAR(255) PRIMARY KEY
);
CREATE TABLE blog_eval (
blog_id VARCHAR(255) REFERENCES blogs(id) ON DELETE CASCADE,
user_id VARCHAR(255) REFERENCES users(id),
is_like BOOLEAN, --true if like / false if dislike
PRIMARY KEY (blog_id, user_id)
);
I need to get all blogs with two additional columns: sum of likes and sum of dislikes.
I am not really sure how to combine a JOIN with the COUNT-Function and also add the logic to distinguish between likes and dislikes.
I am using MySQL.
Thanks for your help!
Comments
Post a Comment