Skip to content
Advertisement

Which cars have been rented together how many times? Which one is more easy to do MySQL or python?

I have a project about github but I represent like rent a car db for better understanding. I must find which cars have been rented together how many times from db. I have a 2 table: rent and car.

I want to like this type of return

I tried some queries to find this but I can’t. Also, I think I can do this with multi dimensional array in python. But If I have a a lot of cars, It can takes a lot of time. Which way is better and optimal?

Advertisement

Answer

This is simple to do in MySQL. To get the counts for any pair of models, use a self-join and aggregation:

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