Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL query - getting a list of counts from a single table

Posted on 2003-12-12
2
Medium Priority
?
394 Views
Last Modified: 2010-05-18
Hey,

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

      count      type
      3      2
      1      3
      2      5
      1      6
where count contains the total number of cars per type?


0
Comment
Question by:mcgettiu
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 9927718
Hi mcgettiu,

Select Type,Count(*) From Cars Group By Type

Is all you need.

Tim Cottee MCSD, MCDBA, CPIM
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 

Author Comment

by:mcgettiu
ID: 9927735
Thanks a mill
You got me out of a jam
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question