1

Customers rent cars, cars are grouped in different categories, 'A - D'

The following queries gets entered to display all vehicle groups rented throughout 2016.

SELECT car_group FROM rentals WHERE checkout_date BETWEEN '2016-01-01' AND '2016-12-30'

The output is as follows:

enter image description here

Now I could run the query and sort the groups via some PHP but I am sure it will be more efficient using a mysql statement...?

I know I can use SELECT count(car_group) as cars but that will return the total sum of cars NOT the amount of different groups.

Any advise appreciated.

Timothy Coetzee
  • 5,626
  • 9
  • 34
  • 97
  • You may try combining `COUNT(*)` and `GROUP BY` – FDavidov Oct 30 '16 at 11:20
  • I think you need `count(distinct car_group)`. Have a look at this question: http://stackoverflow.com/questions/1002349/using-distinct-and-count-together-in-a-mysql-query – Paul Spiegel Oct 30 '16 at 11:44

0 Answers0