I have a table like this
userId story novel
1 a b
1 a b
1 a c
1 b c
1 b c
2 x x
2 x y
2 y y
3 m n
4 NULL NULL
How do I find the most story and novel count per user?
What I am looking for is the highest distinct count of story and novel for each user. So if a user has no story then story_count should be 0.
Desired output looks like this
userId story story_count novel novel_count
1 a 3 c 3
2 x 2 y 2
3 m 1 n 1
4 NULL 0 NULL 0
This is my faulty current attempt
SELECT userId, story, COUNT(story) as story_count, novel, COUNT(novel) as novel_count
FROM logs WHERE user = (SELECT DISTINCT(user)) GROUP BY story, novel;