SQL query - getting a list of counts from a single table
Posted on 2003-12-12
If i have a table 'cars' in my DB something like:
id type color
1 2 blue
2 2 blue
3 3 red
4 6 red
5 5 blue
6 5 blue
7 2 green
If i want to return the total number of entries per type,
and also return the type in the same row.
Is this possible and how would i do it?
Select distinct type from cars.....will return a list of the distinct types
select count(*) from cars as Total.....will return the complete total of all cars
But can i get a result in the following format
where count contains the total number of cars per type?