I need to count and show how many bike-rentals every customer have. Included customers that haven't rented a bike. But how? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I need to count and show how many bike-rentals every customer have. Included customers that haven't rented a bike. But how?

SELECT Customer.MobileNr, COUNT(*) AS NumberOfRentals FROM Customer, Rental WHERE Customer.MobileNr = Rental.MobileNr GROUP BY Customer.MobileNr (This doesn't include customers that haven't rented a bike)

18th Mar 2020, 1:19 PM
W. Khalid
5 Answers
+ 2
// Select all of them and later count them individual by php, or select 2 times
18th Mar 2020, 2:19 PM
Sudarshan Rai
Sudarshan Rai - avatar
+ 2
W. Khalid I have 0 mysql workbench you cand this then: select * from NumberOfRentals where Customer.MobileNr in ('rented', 'notrendet')
18th Mar 2020, 2:29 PM
Sudarshan Rai
Sudarshan Rai - avatar
+ 2
Use a Left outer join: SELECT Customer.MobileNr, COUNT(Rental.MobileNr) AS NumberOfRentals FROM Customer left join Rental On Customer.MobileNr = Rental.MobileNr GROUP BY Customer.MobileNr
18th Mar 2020, 2:45 PM
PapaBT
PapaBT - avatar
0
Sudarshan Rai 👑 I'm doing it on MySql workbench, will it work?
18th Mar 2020, 2:23 PM
W. Khalid
0
PapaBT will this include Customers that doesn't exist in Rental? (haven't rented yet)
18th Mar 2020, 2:59 PM
W. Khalid