Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2003-12-12
2
389 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 125 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

856 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