Stuck on how to approach Albums vs. Tracks query

I am on the final part of the Guided Project for SQL, specifically the Albums vs. Individual Tracks part.

I am just totally lost. I understand conceptually what is happening in all the queries, but up until now, I’ve been heavily relying on the solutions from other programmers and working backwards (I think I learn better and retain more that way).

On this particular query though, I just don’t know where to start. It asks us for the number of invoices, and percentage of invoices, so I know what it wants, but not how to begin.

What’s the first thing I should be attempting? For clarification, this isn’t a technical issue, but a thought-process issue. This SQL section has been infinitely harder than anything I’ve done thus far, and it’s really demotivating. I want to be able to get through this last part without looking at anyone’s answers, but it’s so confusing at times that I feel like it’s the only way.

Can anyone give some insight and/or guidance on this? It would be much appreciated.

Thank you very much!

1 Like


Firstly, your determination to get the answer to this part without looking at the solution is commendable :+1:. Keep that going!!

Secondly, I was in the same situation as you are while I was doing this problem. I got the answer and you will too.

Thirdly it might take more time than you think (it may not be the case for everyone, it just was for me). I was on this problem for about 3 days while on a full time job and a baby that refused to sleep. Funnily enough I was thinking of this problem so much that I got close to the answer during one of my sleepy thinking episodes while putting her to sleep.

So don’t lose heart. You are on Point A and the answer is on Point B. You have all the knowledge required to get across. Everything else is noise, just ignore it and keep moving forward. As long as you are thinking of the problem your brain is constantly working in the background.

Now coming to the point. I would recommend that you read the page on which this problem is presented a couple of times. DQ has quite generously explained how you should go about the problem, it just needs to be implemented.

A couple of clues I got after reading a number of times is

  • Every invoice is either an album invoice(containing tracks from an album) or a non-album invoice( meaning it has a mix of tracks from all the albums)
  • Based on the above, you just need to identify the invoices as album or non-album. For this each invoice line contains track ids and the track ids have associated albums.
  • DQ has provided an example. Think about how you can use that with the tables you have.

You’ll get there bud. Just keep going :rocket:

1 Like

Thank you for your genuine response. I totally understand the explanation given by DQ, but I think most of my confusion is just from how databases work in general. I unfortunately spent all day tinkering with it, but eventually looked at another users solution and I have pored over it line by line several times now, as well as tried to replicate it on my own. It does make more sense, as it lines up with the explanation given by DQ.

Basically in my CASE statement, I had to (very slowly) explain to myself how each line worked.
So my pseudocode looked like this:

  • get list of tracks from invoice
  • compare each track_id from invoice to track_id from album
  • if all track_ids are equal, then it’s an album purchase
  • otherwise, it’s a track purchase

It’s so simple in concept, but I was having the hardest time trying to untangle it in my head. Even now - with an answer that works - I’m finding that I still have to very slowly go through it to make sure I’m understanding the logic behind it all.

No harm done! We are learning. Just keep at it…there is always another project at the next corner.