Skip to content
Advertisement

How can I get the percentage of time per user in sql?

I am making an app where people can select a song and listen to it. Whenever someone plays a song it should display the percentage of the how much youve listened in an overview. I have the following tables:

Song

User

PlayList

I want the result to look like this:

I’ve looked around and found this – this almost answers my question, but not quite.

I want to know the percentage for each song and for each user.

The linked question gives the percentage for each song and for all users. How can I change this?

This is what I have so far:

How can I make this work?

Advertisement

Answer

This query will look like this:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement