Jump to content

Count with sub querry


Recommended Posts

I have this table "plays":  
     
artist title  
artist_1 title_1  
artist_1 title_1  
artist_1 title_2  
artist_2 title_1  
     
I want to have something like this:
     
artist title counts
artist_1 title_1 2
artist_1 title_2 1
artist_2 title_1 1

 

I tried some querries wih SELECT DISTINCT and and GROUP BY but did not get what i wanted.

Do you have any hint for me? I guess i need a sub querry. Thank you!

 

Link to post
Share on other sites
  • 2 weeks later...

Hey there! Welcome to the forums!

This one can be a bit mind boggling. But I did manage to get it to work.

It involves using GROUP BY on both `artist` and `title`. Take a look!

SELECT *, COUNT(title)
FROM plays
GROUP BY artist, title

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...