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)
5 ответов
+ 2
// Select all of them and later count them individual by php, or select 2 times
+ 2
W. Khalid I have 0 mysql workbench you cand this then:
select * from NumberOfRentals where Customer.MobileNr in ('rented', 'notrendet')
+ 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
0
Sudarshan Rai 👑 I'm doing it on MySql workbench, will it work?
0
PapaBT will this include Customers that doesn't exist in Rental? (haven't rented yet)