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.

2
  • You may try combining COUNT(*) and GROUP BY Commented Oct 30, 2016 at 11:20
  • I think you need count(distinct car_group). Have a look at this question: stackoverflow.com/questions/1002349/… Commented Oct 30, 2016 at 11:44

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.